2344
|
1 |
"{ Package: 'stx:goodies/regression' }"
|
|
2 |
|
|
3 |
"{ NameSpace: RegressionTests }"
|
|
4 |
|
|
5 |
TestCase subclass:#SmallDictionaryTest
|
|
6 |
instanceVariableNames:'dictionaryClass'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'tests-Regression-Collections'
|
|
10 |
!
|
|
11 |
|
|
12 |
|
|
13 |
!SmallDictionaryTest class methodsFor:'queries'!
|
|
14 |
|
|
15 |
coveredClassNames
|
|
16 |
^ #( SmallDictionary )
|
|
17 |
! !
|
|
18 |
|
|
19 |
!SmallDictionaryTest methodsFor:'initialize / release'!
|
|
20 |
|
|
21 |
setUp
|
|
22 |
dictionaryClass := SmallDictionary.
|
|
23 |
|
|
24 |
"Created: / 14-09-2018 / 16:38:30 / Stefan Vogel"
|
|
25 |
! !
|
|
26 |
|
|
27 |
!SmallDictionaryTest methodsFor:'testing'!
|
|
28 |
|
|
29 |
test01_AddAll
|
|
30 |
"(self run: #testAddAll)"
|
|
31 |
|
|
32 |
| dict1 dict2 |
|
|
33 |
|
|
34 |
dict1 := dictionaryClass new.
|
|
35 |
self assert:(dict1 isEmpty).
|
|
36 |
self assert:(dict1 size == 0).
|
|
37 |
|
|
38 |
dict1 at: #a put:1 ; at: #b put: 2.
|
|
39 |
dict2 := dictionaryClass new.
|
|
40 |
dict2 at: #a put: 3 ; at: #c put: 4.
|
|
41 |
dict1 addAll: dict2.
|
|
42 |
self assert: (dict1 at: #a) = 3.
|
|
43 |
self assert: (dict1 at: #b) = 2.
|
|
44 |
self assert: (dict1 at: #c) = 4.
|
|
45 |
|
|
46 |
"Modified: / 14-09-2018 / 16:38:54 / Stefan Vogel"
|
|
47 |
!
|
|
48 |
|
|
49 |
test02_AssociationsSelect
|
|
50 |
|
|
51 |
"(self selector: #testAssociationsSelect) run"
|
|
52 |
|
|
53 |
| answer d|
|
|
54 |
|
|
55 |
d := dictionaryClass new.
|
|
56 |
d at: (Array with: #hello with: #world) put: #fooBar.
|
|
57 |
d at: Smalltalk put: #'Smalltalk is the key'.
|
|
58 |
d at: #Smalltalk put: Smalltalk.
|
|
59 |
|
|
60 |
answer := d associationsSelect:
|
|
61 |
[:assoc | (assoc key == #Smalltalk) and: [assoc value == Smalltalk]].
|
|
62 |
self should: [answer isKindOf: dictionaryClass].
|
|
63 |
self should: [answer size == 1].
|
|
64 |
self should: [(answer at: #Smalltalk) == Smalltalk].
|
|
65 |
|
|
66 |
answer := d associationsSelect:
|
|
67 |
[:assoc | (assoc key == #NoSuchKey) and: [assoc value == #NoSuchValue]].
|
|
68 |
self should: [answer isKindOf: dictionaryClass].
|
|
69 |
self should: [answer size == 0]
|
|
70 |
|
|
71 |
"Modified: / 14-09-2018 / 16:39:05 / Stefan Vogel"
|
|
72 |
!
|
|
73 |
|
|
74 |
test03_Comma
|
|
75 |
"(self run: #testComma)"
|
|
76 |
|
|
77 |
| dict1 dict2 dict3 |
|
|
78 |
dict1 := dictionaryClass new.
|
|
79 |
dict1 at: #a put:1 ; at: #b put: 2.
|
|
80 |
dict2 := dictionaryClass new.
|
|
81 |
dict2 at: #a put: 3 ; at: #c put: 4.
|
|
82 |
dict3 := dict1, dict2.
|
|
83 |
self assert: (dict3 at: #a) = 3.
|
|
84 |
self assert: (dict3 at: #b) = 2.
|
|
85 |
self assert: (dict3 at: #c) = 4.
|
|
86 |
|
|
87 |
"Modified: / 14-09-2018 / 16:39:14 / Stefan Vogel"
|
|
88 |
!
|
|
89 |
|
|
90 |
test04_IncludesAssociation
|
|
91 |
"self debug: #testIncludesAssociation"
|
|
92 |
|
|
93 |
| d |
|
|
94 |
d := dictionaryClass new
|
|
95 |
at: #five put: 5;
|
|
96 |
at: #givemefive put: 5;
|
|
97 |
at: #six put: 6;
|
|
98 |
yourself.
|
|
99 |
|
|
100 |
self assert: (d includesAssociation: (d associationAt: #five)).
|
|
101 |
self assert: (d associationAt: #five) key == #five.
|
|
102 |
self assert: (d associationAt: #five) value == 5.
|
|
103 |
self assert: (d includesAssociation: (#five -> 5)).
|
|
104 |
self assert: (d includesAssociation: (#five -> 6)) not.
|
|
105 |
|
|
106 |
"Modified: / 06-12-2016 / 14:19:15 / cg"
|
|
107 |
"Modified: / 14-09-2018 / 16:39:21 / Stefan Vogel"
|
|
108 |
!
|
|
109 |
|
|
110 |
test05_RemoveAllDeclareAll
|
|
111 |
"self debug: #testRemoveAllDeclareAll"
|
|
112 |
|
|
113 |
"/ verifies that we can restore a dictionaries original contents
|
|
114 |
"/ by making a copy of it, then redeclaring from the copy.
|
|
115 |
"/ (needed by the refactorybrowser)
|
|
116 |
|
|
117 |
| d copyOfIt |
|
|
118 |
|
|
119 |
d := dictionaryClass new
|
|
120 |
at: #five put: (5@5);
|
|
121 |
at: #givemefive put: (55@55);
|
|
122 |
at: #six put: (6@6);
|
|
123 |
yourself.
|
|
124 |
|
|
125 |
copyOfIt := d copy.
|
|
126 |
d keysAndValuesDo:[:k :v |
|
|
127 |
self assert: (copyOfIt at:k) == v.
|
|
128 |
].
|
|
129 |
|
|
130 |
"/ add something
|
|
131 |
d at:#seven put:(7@7).
|
|
132 |
|
|
133 |
"/ removeall - redeclare
|
|
134 |
d removeAll; declareAllFrom:copyOfIt.
|
|
135 |
|
|
136 |
self assert: (d size = copyOfIt size).
|
|
137 |
self assert: (d keys = copyOfIt keys).
|
|
138 |
d keysAndValuesDo:[:k :v |
|
|
139 |
self assert: (copyOfIt at:k) == v.
|
|
140 |
].
|
|
141 |
|
|
142 |
"Created: / 06-02-2017 / 12:26:22 / cg"
|
|
143 |
"Modified: / 14-09-2018 / 16:39:28 / Stefan Vogel"
|
|
144 |
!
|
|
145 |
|
|
146 |
test06_AddRemove
|
|
147 |
"self debug: #testRemoveAllDeclareAll"
|
|
148 |
|
|
149 |
"/ verifies that we can restore a dictionaries original contents
|
|
150 |
"/ by making a copy of it, then redeclaring from the copy.
|
|
151 |
"/ (needed by the refactorybrowser)
|
|
152 |
|
|
153 |
| d a |
|
|
154 |
|
|
155 |
d := dictionaryClass new.
|
|
156 |
d at:'a' put:1.
|
|
157 |
self assert:(d includesKey:'a').
|
|
158 |
self assert:d size == 1.
|
|
159 |
self assert:(d instVarNamed:'tally') == 1.
|
|
160 |
|
|
161 |
d at:'b' put:2.
|
|
162 |
self assert:(d includesKey:'a').
|
|
163 |
self assert:(d includesKey:'b').
|
|
164 |
self assert:d size == 2.
|
|
165 |
self assert:(d instVarNamed:'tally') == 2.
|
|
166 |
|
|
167 |
d at:'c' put:3.
|
|
168 |
self assert:(d includesKey:'a').
|
|
169 |
self assert:(d includesKey:'b').
|
|
170 |
self assert:(d includesKey:'c').
|
|
171 |
self assert:(d at:'a') == 1.
|
|
172 |
self assert:(d at:'b') == 2.
|
|
173 |
self assert:(d at:'c') == 3.
|
|
174 |
self assert:d size == 3.
|
|
175 |
self assert:(d instVarNamed:'tally') == 3.
|
|
176 |
self assert:(d order = #('a' 'b' 'c')).
|
|
177 |
|
|
178 |
d removeKey:'b'.
|
|
179 |
self assert:(d includesKey:'a').
|
|
180 |
self assert:(d includesKey:'b') not.
|
|
181 |
self assert:(d includesKey:'c').
|
|
182 |
self assert:(d at:'a') == 1.
|
|
183 |
self assert:(d at:'b' ifAbsent:nil) isNil.
|
|
184 |
self assert:(d at:'c') == 3.
|
|
185 |
self assert:d size == 2.
|
|
186 |
self assert:(d instVarNamed:'tally') == 2.
|
|
187 |
a := (d instVarNamed:'keysAndValues').
|
|
188 |
self assert:(a = #('a' 1 'c' 3 nil nil nil nil)).
|
|
189 |
self assert:(d order = #('a' 'c')).
|
|
190 |
!
|
|
191 |
|
|
192 |
test07_AddAssoc
|
|
193 |
| d |
|
|
194 |
|
|
195 |
d := dictionaryClass new.
|
|
196 |
d add:('a' -> 1).
|
|
197 |
d add:('b' -> 2).
|
|
198 |
d add:('c' -> 3).
|
|
199 |
|
|
200 |
d at:'c' put:3.
|
|
201 |
self assert:(d includesKey:'a').
|
|
202 |
self assert:(d includesKey:'b').
|
|
203 |
self assert:(d includesKey:'c').
|
|
204 |
self assert:(d at:'a') == 1.
|
|
205 |
self assert:(d at:'b') == 2.
|
|
206 |
self assert:(d at:'c') == 3.
|
|
207 |
self assert:d size == 3.
|
|
208 |
|
|
209 |
self assert:(d order = #('a' 'b' 'c')).
|
|
210 |
|
|
211 |
!
|
|
212 |
|
|
213 |
test08_Do
|
|
214 |
| d coll |
|
|
215 |
|
|
216 |
d := dictionaryClass new.
|
|
217 |
d add:('a' -> 1).
|
|
218 |
d add:('b' -> 2).
|
|
219 |
d add:('c' -> 3).
|
|
220 |
|
|
221 |
coll := OrderedCollection new.
|
|
222 |
d do:[:each |
|
|
223 |
coll add:each
|
|
224 |
].
|
|
225 |
self assert:(coll sameContentsAs:#(1 2 3)).
|
|
226 |
|
|
227 |
d removeKey:'a'.
|
|
228 |
coll := OrderedCollection new.
|
|
229 |
d do:[:each |
|
|
230 |
coll add:each
|
|
231 |
].
|
|
232 |
self assert:(coll sameContentsAs:#(2 3)).
|
|
233 |
!
|
|
234 |
|
|
235 |
test08_KeysAndValuesDo
|
|
236 |
| d coll |
|
|
237 |
|
|
238 |
d := dictionaryClass new.
|
|
239 |
d add:('a' -> 1).
|
|
240 |
d add:('b' -> 2).
|
|
241 |
d add:('c' -> 3).
|
|
242 |
|
|
243 |
coll := OrderedCollection new.
|
|
244 |
d keysAndValuesDo:[:eachKey :eachValue |
|
|
245 |
coll add:eachKey.
|
|
246 |
coll add:eachValue.
|
|
247 |
].
|
|
248 |
self assert:(coll sameContentsAs:#('a' 1 'b' 2 'c' 3)).
|
|
249 |
|
|
250 |
d removeKey:'a'.
|
|
251 |
coll := OrderedCollection new.
|
|
252 |
d keysAndValuesDo:[:eachKey :eachValue |
|
|
253 |
coll add:eachKey.
|
|
254 |
coll add:eachValue.
|
|
255 |
].
|
|
256 |
self assert:(coll sameContentsAs:#('b' 2 'c' 3)).
|
|
257 |
!
|
|
258 |
|
|
259 |
test08_KeysDo
|
|
260 |
| d coll |
|
|
261 |
|
|
262 |
d := dictionaryClass new.
|
|
263 |
d add:('a' -> 1).
|
|
264 |
d add:('b' -> 2).
|
|
265 |
d add:('c' -> 3).
|
|
266 |
|
|
267 |
coll := OrderedCollection new.
|
|
268 |
d keysDo:[:eachKey |
|
|
269 |
coll add:eachKey.
|
|
270 |
].
|
|
271 |
self assert:(coll sameContentsAs:#('a' 'b' 'c' )).
|
|
272 |
|
|
273 |
d removeKey:'a'.
|
|
274 |
coll := OrderedCollection new.
|
|
275 |
d keysDo:[:eachKey |
|
|
276 |
coll add:eachKey.
|
|
277 |
].
|
|
278 |
self assert:(coll sameContentsAs:#('b' 'c' )).
|
|
279 |
! !
|
|
280 |
|
|
281 |
!SmallDictionaryTest class methodsFor:'documentation'!
|
|
282 |
|
|
283 |
version_CVS
|
|
284 |
^ '$Header$'
|
|
285 |
! !
|
|
286 |
|