• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pharo-containers / Containers-HashTable / 14488176150

16 Apr 2025 08:25AM UTC coverage: 77.629%. Remained the same
14488176150

push

github

web-flow
Merge pull request #5 from pankaj-bind/fix-issue-3

Refactor CTHashSetTest to use Pharo traits for modularity and reuse

465 of 599 relevant lines covered (77.63%)

0.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.14
/Containers-HashTable/CTHashSet.class.st
1
Class {
2
        #name : #CTHashSet,
3
        #superclass : #CTHashTable,
4
        #category : #'Containers-HashTable-Hash'
5
}
6

7
{ #category : #comparing }
8
CTHashSet >> = aSet [
1✔
9
        self == aSet ifTrue: [^ true].        "stop recursion"
1✔
10
        ((aSet isKindOf: Set) or: [ aSet isKindOf: CTHashSet ])
1✔
11
                ifFalse: [^ false].
1✔
12
        self size = aSet size ifFalse: [^ false].
1✔
13
        self do: [:each | (aSet includes: each) ifFalse: [^ false]].
1✔
14
        ^ true
1✔
15
]
1✔
16

17
{ #category : #adding }
18
CTHashSet >> add: newObject [
1✔
19
        newObject ifNil: [self error: 'Sets cannot meaningfully contain nil as an element'].
1✔
20
        self at: newObject put: true.
1✔
21
        ^ newObject
1✔
22
]
1✔
23

24
{ #category : #adding }
25
CTHashSet >> addAll: aCollection [ 
×
26
        "Include all the elements of aCollection as the receiver's elements. Answer 
×
27
        aCollection. Actually, any object responding to #do: can be used as argument."
×
28

×
29
        aCollection do: [:each | self add: each].
×
30
        ^ aCollection
×
31
]
×
32

33
{ #category : #converting }
34
CTHashSet >> asSet [
×
35
        ^self
×
36
]
×
37

38
{ #category : #enumerating }
39
CTHashSet >> collect: aBlock [ 
×
40
        "Evaluate aBlock with each of the receiver's elements as the argument.  
×
41
        Collect the resulting values into a collection like the receiver. Answer  
×
42
        the new collection."
×
43

×
44
        | newCollection |
×
45
        newCollection := self species new.
×
46
        self do: [:each | newCollection add: (aBlock value: each)].
×
47
        ^ newCollection
×
48
]
×
49

50
{ #category : #enumerating }
51
CTHashSet >> do: aBlock [
1✔
52
        
1✔
53
        self keysAndValuesDo: [ :key :value | aBlock value: key ]
1✔
54
]
1✔
55

56
{ #category : #testing }
57
CTHashSet >> includes: anObject [
1✔
58
        ^self at: anObject ifAbsent: [ false ]
1✔
59
]
1✔
60

61
{ #category : #testing }
62
CTHashSet >> occurrencesOf: anObject [ 
×
63
        ^ (self includes: anObject) ifTrue: [1] ifFalse: [0]
×
64
]
×
65

66
{ #category : #printing }
67
CTHashSet >> printOn: aStream [ 
1✔
68

1✔
69
        | title |
1✔
70
        title := self class name.
1✔
71
        aStream
1✔
72
                nextPutAll: (title first isVowel ifTrue: ['an '] ifFalse: ['a ']);
1✔
73
                nextPutAll: title.
1✔
74
        
1✔
75
        "printElementsOn:"
1✔
76
        aStream nextPut: $(.
1✔
77
        self do: [:element | aStream print: element; space].
1✔
78
        self isEmpty ifFalse: [aStream skip: -1].
1✔
79
        aStream nextPut: $)
1✔
80
]
1✔
81

82
{ #category : #removing }
83
CTHashSet >> remove: oldObject ifAbsent: anExceptionBlock [
1✔
84
        ^self removeKey: oldObject ifAbsent: anExceptionBlock.
1✔
85
]
1✔
86

87
{ #category : #enumerating }
88
CTHashSet >> select: aBlock [ 
1✔
89
        "Evaluate aBlock with each of the receiver's elements as the argument. 
1✔
90
        Collect into a new collection like the receiver, only those elements for 
1✔
91
        which aBlock evaluates to true. Answer the new collection."
1✔
92

1✔
93
        | newCollection |
1✔
94
        newCollection := self species new.
1✔
95
        self do: [:each | (aBlock value: each) ifTrue: [newCollection add: each]].
1✔
96
        ^newCollection
1✔
97
]
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc