115
|
1 |
"{ Package: 'exept:regression' }"
|
|
2 |
|
157
|
3 |
"{ NameSpace: RegressionTests }"
|
|
4 |
|
115
|
5 |
TestCase subclass:#CollectionTests
|
293
|
6 |
instanceVariableNames:'empty nonEmpty'
|
115
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
181
|
9 |
category:'tests-Regression'
|
115
|
10 |
!
|
|
11 |
|
212
|
12 |
Object subclass:#SortTestData
|
|
13 |
instanceVariableNames:'value order'
|
|
14 |
classVariableNames:''
|
|
15 |
poolDictionaries:''
|
|
16 |
privateIn:CollectionTests
|
|
17 |
!
|
|
18 |
|
115
|
19 |
!CollectionTests class methodsFor:'documentation'!
|
|
20 |
|
585
|
21 |
coveredClasses
|
|
22 |
^ Collection withAllSubclasses
|
|
23 |
!
|
|
24 |
|
115
|
25 |
documentation
|
|
26 |
"
|
|
27 |
documentation to be added.
|
|
28 |
|
|
29 |
[author:]
|
|
30 |
Claus Gittinger (cg@alan)
|
|
31 |
|
|
32 |
[see also:]
|
|
33 |
|
|
34 |
[instance variables:]
|
|
35 |
|
|
36 |
[class variables:]
|
|
37 |
"
|
|
38 |
!
|
|
39 |
|
|
40 |
history
|
|
41 |
"Created: / 8.11.2001 / 08:17:09 / cg"
|
|
42 |
! !
|
|
43 |
|
301
|
44 |
!CollectionTests methodsFor:'helpers'!
|
|
45 |
|
|
46 |
collectedDoArgsOf:aCollection
|
|
47 |
|collectedDoArgs|
|
|
48 |
|
|
49 |
collectedDoArgs := OrderedCollection new.
|
|
50 |
aCollection do:[:each | collectedDoArgs add:each].
|
|
51 |
^ collectedDoArgs
|
|
52 |
! !
|
|
53 |
|
293
|
54 |
!CollectionTests methodsFor:'initialize-release'!
|
|
55 |
|
|
56 |
setUp
|
295
|
57 |
empty := Set new.
|
|
58 |
nonEmpty := OrderedCollection with: #x.
|
293
|
59 |
! !
|
|
60 |
|
264
|
61 |
!CollectionTests methodsFor:'tests-dictionary'!
|
115
|
62 |
|
|
63 |
testDictionary01
|
301
|
64 |
|d v1 v2 v3 ret|
|
115
|
65 |
|
|
66 |
d := Dictionary new.
|
|
67 |
d at:1 put:(v1 := 'one').
|
|
68 |
d at:2 put:(v2 := 'two').
|
|
69 |
d at:3 put:(v3 := 'three').
|
|
70 |
|
|
71 |
self assert: ( d size == 3 ).
|
301
|
72 |
|
585
|
73 |
self assert:(ret := self collectedDoArgsOf:d) asArray = #('one' 'two' 'three').
|
301
|
74 |
self assert:(ret := d collect:[:each | each]) = #('one' 'two' 'three') asBag.
|
|
75 |
self assert:(ret := d select:[:each | true]) = (Dictionary withAssociations:(Array with:(1->'one') with:(2->'two') with:(3->'three'))).
|
|
76 |
|
115
|
77 |
self assert: ( (d at:1) == v1 ).
|
|
78 |
self assert: ( (d at:2) == v2 ).
|
|
79 |
self assert: ( (d at:3) == v3 ).
|
|
80 |
|
|
81 |
d at:3 put:(v3 := 'drei').
|
|
82 |
|
|
83 |
self assert: ( d size == 3 ).
|
|
84 |
|
|
85 |
self assert: ( (d at:1) == v1 ).
|
|
86 |
self assert: ( (d at:2) == v2 ).
|
|
87 |
self assert: ( (d at:3) == v3 ).
|
|
88 |
|
|
89 |
self assert: ( (d keyAtValue:v1) = 1 ).
|
|
90 |
|
|
91 |
"
|
|
92 |
self basicNew testDictionary01
|
|
93 |
"
|
585
|
94 |
|
|
95 |
"Modified: / 04-07-2011 / 19:28:39 / cg"
|
264
|
96 |
! !
|
|
97 |
|
|
98 |
!CollectionTests methodsFor:'tests-general'!
|
|
99 |
|
615
|
100 |
doTestDictionaryLikeAddRemoveOperationsIn:aClass
|
|
101 |
|coll|
|
|
102 |
|
|
103 |
coll := aClass new.
|
|
104 |
|
|
105 |
self assert: ( coll size == 0 ).
|
|
106 |
self assert: ( coll isEmpty ).
|
|
107 |
self assert: ( coll notEmpty not ).
|
|
108 |
self assert: ( coll isEmptyOrNil ).
|
|
109 |
self assert: ( coll notEmptyOrNil not ).
|
|
110 |
|
|
111 |
coll at:1 put:'one'.
|
|
112 |
|
|
113 |
self assert: ( coll size == 1 ).
|
|
114 |
self assert: ( coll isEmpty not).
|
|
115 |
self assert: ( coll notEmpty ).
|
|
116 |
self assert: ( coll isEmptyOrNil not ).
|
|
117 |
self assert: ( coll notEmptyOrNil ).
|
|
118 |
|
|
119 |
coll at:2 put:'two'.
|
|
120 |
|
|
121 |
self assert: ( coll size == 2 ).
|
|
122 |
self assert: ( coll isEmpty not).
|
|
123 |
self assert: ( coll notEmpty ).
|
|
124 |
self assert: ( coll isEmptyOrNil not ).
|
|
125 |
self assert: ( coll notEmptyOrNil ).
|
|
126 |
|
|
127 |
coll removeKey:2.
|
|
128 |
self assert: ( coll size == 1 ).
|
|
129 |
self assert: ( coll isEmpty not).
|
|
130 |
self assert: ( coll notEmpty ).
|
|
131 |
self assert: ( coll isEmptyOrNil not ).
|
|
132 |
self assert: ( coll notEmptyOrNil ).
|
|
133 |
|
|
134 |
coll removeKey:1.
|
|
135 |
self assert: ( coll size == 0 ).
|
|
136 |
self assert: ( coll isEmpty ).
|
|
137 |
self assert: ( coll notEmpty not ).
|
|
138 |
self assert: ( coll isEmptyOrNil ).
|
|
139 |
self assert: ( coll notEmptyOrNil not ).
|
|
140 |
|
|
141 |
"
|
|
142 |
self basicNew doTestDictionaryLikeAddRemoveOperations
|
|
143 |
"
|
|
144 |
|
|
145 |
"Created: / 08-08-2011 / 16:01:14 / cg"
|
|
146 |
!
|
|
147 |
|
|
148 |
doTestGeneralAddRemoveOperationsIn:aClass
|
|
149 |
|coll|
|
|
150 |
|
|
151 |
coll := aClass new.
|
|
152 |
|
|
153 |
self assert: ( coll size == 0 ).
|
|
154 |
self assert: ( coll isEmpty ).
|
|
155 |
self assert: ( coll notEmpty not ).
|
|
156 |
self assert: ( coll isEmptyOrNil ).
|
|
157 |
self assert: ( coll notEmptyOrNil not ).
|
|
158 |
|
|
159 |
coll add:1.
|
|
160 |
|
|
161 |
self assert: ( coll size == 1 ).
|
|
162 |
self assert: ( coll isEmpty not).
|
|
163 |
self assert: ( coll notEmpty ).
|
|
164 |
self assert: ( coll isEmptyOrNil not ).
|
|
165 |
self assert: ( coll notEmptyOrNil ).
|
|
166 |
|
|
167 |
coll add:2.
|
|
168 |
|
|
169 |
self assert: ( coll size == 2 ).
|
|
170 |
self assert: ( coll isEmpty not).
|
|
171 |
self assert: ( coll notEmpty ).
|
|
172 |
self assert: ( coll isEmptyOrNil not ).
|
|
173 |
self assert: ( coll notEmptyOrNil ).
|
|
174 |
|
|
175 |
coll remove:2.
|
|
176 |
self assert: ( coll size == 1 ).
|
|
177 |
self assert: ( coll isEmpty not).
|
|
178 |
self assert: ( coll notEmpty ).
|
|
179 |
self assert: ( coll isEmptyOrNil not ).
|
|
180 |
self assert: ( coll notEmptyOrNil ).
|
|
181 |
|
|
182 |
coll remove:1.
|
|
183 |
self assert: ( coll size == 0 ).
|
|
184 |
self assert: ( coll isEmpty ).
|
|
185 |
self assert: ( coll notEmpty not ).
|
|
186 |
self assert: ( coll isEmptyOrNil ).
|
|
187 |
self assert: ( coll notEmptyOrNil not ).
|
|
188 |
|
|
189 |
"
|
|
190 |
self basicNew testGeneralOperations
|
|
191 |
"
|
|
192 |
|
|
193 |
"Created: / 08-08-2011 / 16:00:06 / cg"
|
|
194 |
!
|
|
195 |
|
264
|
196 |
doTestGeneralCollectionOperationsIn:aClass
|
|
197 |
|coll|
|
|
198 |
|
|
199 |
coll := aClass new.
|
|
200 |
|
|
201 |
self assert: ( coll size == 0 ).
|
|
202 |
self assert: ( coll isEmpty ).
|
|
203 |
self assert: ( coll notEmpty not ).
|
|
204 |
self assert: ( coll isEmptyOrNil ).
|
|
205 |
self assert: ( coll notEmptyOrNil not ).
|
|
206 |
|
|
207 |
self should: [ coll first ] raise:Error.
|
|
208 |
self should: [ coll last ] raise:Error.
|
|
209 |
self should: [ (coll at:1) ] raise:Error.
|
|
210 |
|
|
211 |
self assert: ( (coll includes:0) not ).
|
|
212 |
|
|
213 |
"
|
|
214 |
self basicNew testGeneralOperations
|
|
215 |
"
|
156
|
216 |
!
|
|
217 |
|
615
|
218 |
testDictionaryLikeAddRemoveOperations
|
|
219 |
|classes|
|
|
220 |
|
|
221 |
classes := OrderedCollection new.
|
|
222 |
classes
|
|
223 |
add:Dictionary;
|
|
224 |
add:IdentityDictionary;
|
|
225 |
add:OrderedDictionary;
|
|
226 |
add:BTree.
|
|
227 |
|
|
228 |
classes do:[:eachClass |
|
|
229 |
self doTestDictionaryLikeAddRemoveOperationsIn:eachClass
|
|
230 |
].
|
|
231 |
|
|
232 |
"
|
|
233 |
self basicNew testDictionaryLikeAddRemoveOperations
|
|
234 |
"
|
|
235 |
|
|
236 |
"Created: / 08-08-2011 / 15:59:52 / cg"
|
|
237 |
!
|
|
238 |
|
|
239 |
testGeneralAddRemoveOperations
|
|
240 |
|classes|
|
|
241 |
|
|
242 |
classes := OrderedCollection new.
|
|
243 |
classes
|
|
244 |
"/ add:RunArray;
|
|
245 |
add:Bag;
|
|
246 |
add:Set;
|
|
247 |
add:IdentitySet;
|
|
248 |
"/add:Dictionary;
|
|
249 |
"/add:IdentityDictionary;
|
|
250 |
add:OrderedCollection;
|
|
251 |
add:SortedCollection;
|
|
252 |
"/add:Queue;
|
|
253 |
"/add:Stack;
|
|
254 |
add:SortedCollection;
|
|
255 |
"/add:OrderedDictionary;
|
|
256 |
add:OrderedSet.
|
|
257 |
"/add:BTree.
|
|
258 |
|
|
259 |
classes do:[:eachClass |
|
|
260 |
self doTestGeneralAddRemoveOperationsIn:eachClass
|
|
261 |
].
|
|
262 |
|
|
263 |
"
|
|
264 |
self basicNew testGeneralAddRemoveOperations
|
|
265 |
"
|
|
266 |
|
|
267 |
"Created: / 08-08-2011 / 15:59:02 / cg"
|
|
268 |
!
|
|
269 |
|
264
|
270 |
testGeneralOperations
|
|
271 |
|classes|
|
|
272 |
|
|
273 |
classes := OrderedCollection new.
|
|
274 |
classes
|
|
275 |
add:RunArray;
|
|
276 |
add:Bag;
|
|
277 |
add:Set;
|
|
278 |
add:IdentitySet;
|
|
279 |
add:Dictionary;
|
|
280 |
add:IdentityDictionary;
|
|
281 |
add:OrderedCollection;
|
|
282 |
add:SortedCollection;
|
|
283 |
add:Queue;
|
|
284 |
add:Stack;
|
|
285 |
add:SortedCollection;
|
|
286 |
add:OrderedDictionary;
|
615
|
287 |
add:OrderedSet;
|
|
288 |
add:BTree.
|
264
|
289 |
|
|
290 |
classes do:[:eachClass |
|
|
291 |
self doTestGeneralCollectionOperationsIn:eachClass
|
|
292 |
].
|
|
293 |
|
|
294 |
"
|
|
295 |
self basicNew testGeneralOperations
|
|
296 |
"
|
615
|
297 |
|
|
298 |
"Modified: / 08-08-2011 / 15:53:16 / cg"
|
264
|
299 |
! !
|
|
300 |
|
|
301 |
!CollectionTests methodsFor:'tests-interval'!
|
|
302 |
|
162
|
303 |
testInterval01
|
644
|
304 |
|i1 i2|
|
162
|
305 |
|
644
|
306 |
i1 := 1 to:10.
|
162
|
307 |
|
644
|
308 |
self assert: ( i1 size == 10 ).
|
162
|
309 |
|
644
|
310 |
self assert: ( i1 includes:1 ).
|
|
311 |
self assert: ( i1 includes:10 ).
|
162
|
312 |
|
644
|
313 |
self assert: ( i1 min == 1 ).
|
|
314 |
self assert: ( i1 max == 10 ).
|
162
|
315 |
|
|
316 |
"cannot add/remove"
|
644
|
317 |
self should:[i1 add:99] raise:Error.
|
|
318 |
self should:[i1 remove:10] raise:Error.
|
|
319 |
|
|
320 |
i2 := 2 to:20 by:2.
|
|
321 |
self assert: ( i2 size == 10 ).
|
|
322 |
|
|
323 |
self assert: ( i2 includes:0 ) not.
|
|
324 |
self assert: ( i2 includes:1 ) not.
|
|
325 |
self assert: ( i2 includes:2 ).
|
|
326 |
self assert: ( i2 includes:3 ) not.
|
|
327 |
self assert: ( i2 includes:10 ).
|
|
328 |
self assert: ( i2 includes:19 ) not.
|
|
329 |
self assert: ( i2 includes:20 ).
|
|
330 |
self assert: ( i2 includes:21 ) not.
|
|
331 |
self assert: ( i2 includes:22 ) not.
|
|
332 |
|
|
333 |
self assert: ( i2 min == 2 ).
|
|
334 |
self assert: ( i2 max == 20 ).
|
|
335 |
|
|
336 |
self assert: ( i2 keys asArray = (1 to:10) asArray ).
|
162
|
337 |
|
|
338 |
"
|
|
339 |
self basicNew testInterval01
|
|
340 |
"
|
644
|
341 |
|
|
342 |
"Modified: / 10-10-2011 / 13:10:43 / cg"
|
264
|
343 |
! !
|
|
344 |
|
301
|
345 |
!CollectionTests methodsFor:'tests-orderedCollection'!
|
|
346 |
|
|
347 |
testOrderedCollection01_Sort1
|
|
348 |
|col col2|
|
|
349 |
|
|
350 |
col := #( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ) copy.
|
|
351 |
col sort.
|
585
|
352 |
self assert:( col sameContentsAs: (1 to:20)).
|
301
|
353 |
|
|
354 |
col := #( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ) copy reverse.
|
|
355 |
col sort.
|
585
|
356 |
self assert:( col sameContentsAs: (1 to:20) ).
|
301
|
357 |
|
|
358 |
col := #( 10 2 13 4 15 6 17 8 19 11 1 12 3 14 5 16 7 18 9 20 ) copy.
|
|
359 |
col sort.
|
585
|
360 |
self assert:( col sameContentsAs: (1 to:20) ).
|
301
|
361 |
|
|
362 |
col := ( 1 to: 10000 ) asOrderedCollection.
|
|
363 |
col sort.
|
585
|
364 |
self assert:( col sameContentsAs: (1 to:10000) ).
|
301
|
365 |
|
|
366 |
col := ( 1 to: 10000 ) asOrderedCollection.
|
|
367 |
col2 := ( 1 to: 10000 ) asOrderedCollection.
|
|
368 |
col sortWith:col2.
|
585
|
369 |
self assert:( col sameContentsAs: (1 to:10000) ).
|
|
370 |
self assert:( col2 sameContentsAs: (1 to:10000) ).
|
301
|
371 |
|
|
372 |
col := ( 10000 to: 1 by:-1) asOrderedCollection.
|
|
373 |
col2 := ( 10000 to: 1 by:-1) asOrderedCollection.
|
|
374 |
col sortWith:col2.
|
585
|
375 |
self assert:( col sameContentsAs: (1 to:10000) ).
|
|
376 |
self assert:( col2 sameContentsAs: (1 to:10000) ).
|
301
|
377 |
|
|
378 |
"
|
|
379 |
self new testOrderedCollection01_Sort1
|
|
380 |
"
|
585
|
381 |
|
|
382 |
"Modified: / 04-07-2011 / 19:29:54 / cg"
|
301
|
383 |
!
|
|
384 |
|
|
385 |
testOrderedCollection02_SortBigCollection
|
|
386 |
| size col sortBlock|
|
|
387 |
|
|
388 |
size := 12500.
|
|
389 |
col := OrderedCollection new.
|
|
390 |
1 to:size do:[:el|
|
|
391 |
col add:nil.
|
|
392 |
].
|
|
393 |
sortBlock := [:entry1 :entry2 |
|
|
394 |
((entry1 isNil) or:[entry2 isNil]) ifTrue:[
|
|
395 |
true
|
|
396 |
] ifFalse:[
|
|
397 |
false
|
|
398 |
]
|
|
399 |
].
|
|
400 |
self shouldnt:[col sort:sortBlock] raise:RecursionInterruptSignal.
|
|
401 |
|
|
402 |
"
|
|
403 |
self new testOrderedCollection02_SortBigCollection
|
|
404 |
"
|
|
405 |
!
|
|
406 |
|
|
407 |
testOrderedCollection03_SortBigCollection2
|
|
408 |
| size col|
|
|
409 |
|
|
410 |
size := 12500.
|
|
411 |
col := OrderedCollection new.
|
|
412 |
1 to:size do:[:el|
|
|
413 |
col add:'abc'.
|
|
414 |
].
|
|
415 |
self shouldnt:[col sort] raise:RecursionInterruptSignal.
|
|
416 |
|
|
417 |
"
|
|
418 |
self new testOrderedCollection03_SortBigCollection2
|
|
419 |
"
|
|
420 |
!
|
|
421 |
|
|
422 |
testOrderedCollection04_SortNilsInCollection
|
|
423 |
| size col sortBlock|
|
|
424 |
|
|
425 |
size := 125.
|
|
426 |
col := OrderedCollection new.
|
|
427 |
1 to:size do:[:el|
|
|
428 |
col add:nil.
|
|
429 |
].
|
|
430 |
sortBlock := [:entry1 :entry2 |
|
|
431 |
((entry1 isNil) or:[entry2 isNil]) ifTrue:[
|
|
432 |
true
|
|
433 |
] ifFalse:[
|
|
434 |
false
|
|
435 |
]
|
|
436 |
].
|
|
437 |
"/ col sort:sortBlock.
|
|
438 |
self shouldnt:[col sort:sortBlock] raise:RecursionInterruptSignal.
|
|
439 |
|
|
440 |
"
|
|
441 |
self new testOrderedCollection04_SortNilsInCollection
|
|
442 |
"
|
|
443 |
! !
|
|
444 |
|
|
445 |
!CollectionTests methodsFor:'tests-orderedDictionary'!
|
|
446 |
|
|
447 |
testOrderedDictionary01
|
|
448 |
|d ret|
|
|
449 |
|
|
450 |
d := OrderedDictionary new.
|
|
451 |
|
|
452 |
self assert: ( d size == 0 ).
|
|
453 |
self assert: ( d isEmpty ).
|
|
454 |
self assert: ( d notEmpty not ).
|
|
455 |
|
|
456 |
d at:'one' put:1.
|
|
457 |
d at:'two' put:2.
|
|
458 |
d at:'three' put:3.
|
|
459 |
|
|
460 |
self assert: ( d size == 3 ).
|
|
461 |
self assert: ( d isEmpty not).
|
|
462 |
self assert: ( d notEmpty ).
|
|
463 |
|
585
|
464 |
self assert:((ret := self collectedDoArgsOf:d) sameContentsAs: #(1 2 3)).
|
301
|
465 |
|
|
466 |
self assert: ( (d atIndex:1) == 1 ).
|
|
467 |
self assert: ( (d atIndex:2) == 2 ).
|
|
468 |
self assert: ( (d atIndex:3) == 3 ).
|
|
469 |
|
|
470 |
self assert: ( (d first) = ('one'->1) ).
|
|
471 |
self assert: ( (d last) = ('three'->3) ).
|
|
472 |
|
585
|
473 |
self assert:((ret := d collect:[:each | each]) sameContentsAs: #(1 2 3)).
|
|
474 |
self assert:((ret := d select:[:each | true]) sameContentsAs: (OrderedDictionary withAssociations:(Array with:('one'->1) with:('two'->2) with:('three'->3)))).
|
301
|
475 |
|
|
476 |
self assert: ( d includes:1 ).
|
|
477 |
self assert: ( d includes:2 ).
|
|
478 |
self assert: ( d includes:3 ).
|
|
479 |
|
|
480 |
self assert: ( d includesKey:'one' ).
|
|
481 |
self assert: ( d includesKey:'two' ).
|
|
482 |
self assert: ( d includesKey:'three' ).
|
|
483 |
|
|
484 |
self assert: ((ret := d removeFirst) = 1).
|
|
485 |
self assert: ( d size == 2 ).
|
|
486 |
self assert: ((ret := d removeLast) = 3).
|
|
487 |
self assert: ( d size == 1 ).
|
|
488 |
self assert: ((ret := d removeLast) = 2).
|
|
489 |
self assert: ( d size == 0 ).
|
|
490 |
self assert: ( d isEmpty ).
|
|
491 |
self assert: ( d notEmpty not ).
|
|
492 |
|
|
493 |
"
|
|
494 |
self basicNew testOrderedDictionary01
|
|
495 |
"
|
585
|
496 |
|
|
497 |
"Modified: / 04-07-2011 / 19:32:34 / cg"
|
301
|
498 |
! !
|
|
499 |
|
|
500 |
!CollectionTests methodsFor:'tests-orderedSet'!
|
162
|
501 |
|
156
|
502 |
testOrderedSet01
|
|
503 |
|s v1 v2 v3|
|
|
504 |
|
|
505 |
s := OrderedSet new.
|
|
506 |
s add:(v1 := 'one').
|
|
507 |
s add:(v2 := 'two').
|
|
508 |
s add:(v3 := 'three').
|
|
509 |
|
|
510 |
self assert: ( s size == 3 ).
|
|
511 |
self assert: ( (s at:1) == v1 ).
|
|
512 |
self assert: ( (s at:2) == v2 ).
|
|
513 |
self assert: ( (s at:3) == v3 ).
|
|
514 |
|
|
515 |
self assert: ( s includes:v1 ).
|
|
516 |
self assert: ( s includes:v2 ).
|
|
517 |
self assert: ( s includes:v3 ).
|
|
518 |
|
|
519 |
self assert: ( s includes:v1 copy).
|
|
520 |
self assert: ( s includes:v2 copy).
|
|
521 |
self assert: ( s includes:v3 copy).
|
|
522 |
|
|
523 |
"already in - adding again should not change things"
|
|
524 |
s add:v1.
|
|
525 |
self assert: ( s size == 3 ).
|
|
526 |
|
|
527 |
self assert: ( (s at:1) == v1 ).
|
|
528 |
self assert: ( (s at:2) == v2 ).
|
|
529 |
self assert: ( (s at:3) == v3 ).
|
|
530 |
|
|
531 |
"set i.e. not identitySet - adding copy should not change things"
|
|
532 |
s add:v1 copy.
|
|
533 |
self assert: ( s size == 3 ).
|
|
534 |
|
|
535 |
self assert: ( (s at:1) == v1 ).
|
|
536 |
self assert: ( (s at:2) == v2 ).
|
|
537 |
self assert: ( (s at:3) == v3 ).
|
|
538 |
|
|
539 |
s remove:v1.
|
|
540 |
|
|
541 |
self assert: ( s size == 2 ).
|
|
542 |
self assert: ( (s at:1) == v2 ).
|
|
543 |
self assert: ( (s at:2) == v3 ).
|
|
544 |
|
|
545 |
self assert: ( s includes:v1 ) not.
|
|
546 |
self assert: ( s includes:v2 ).
|
|
547 |
self assert: ( s includes:v3 ).
|
|
548 |
|
|
549 |
self assert: ( s includes:v1 copy) not.
|
|
550 |
self assert: ( s includes:v2 copy).
|
|
551 |
self assert: ( s includes:v3 copy).
|
|
552 |
|
|
553 |
s add:v1.
|
|
554 |
|
|
555 |
self assert: ( s size == 3 ).
|
|
556 |
self assert: ( (s at:1) == v2 ).
|
|
557 |
self assert: ( (s at:2) == v3 ).
|
|
558 |
self assert: ( (s at:3) == v1 ).
|
|
559 |
|
|
560 |
self assert: ( s includes:v1 ).
|
|
561 |
self assert: ( s includes:v2 ).
|
|
562 |
self assert: ( s includes:v3 ).
|
|
563 |
|
|
564 |
self assert: ( s includes:v1 copy).
|
|
565 |
self assert: ( s includes:v2 copy).
|
|
566 |
self assert: ( s includes:v3 copy).
|
|
567 |
|
|
568 |
s removeLast.
|
|
569 |
|
|
570 |
self assert: ( s size == 2 ).
|
|
571 |
self assert: ( (s at:1) == v2 ).
|
|
572 |
self assert: ( (s at:2) == v3 ).
|
|
573 |
|
|
574 |
self assert: ( s includes:v1 ) not.
|
|
575 |
self assert: ( s includes:v2 ).
|
|
576 |
self assert: ( s includes:v3 ).
|
|
577 |
|
|
578 |
self assert: ( s includes:v1 copy) not.
|
|
579 |
self assert: ( s includes:v2 copy).
|
|
580 |
self assert: ( s includes:v3 copy).
|
|
581 |
|
|
582 |
"
|
|
583 |
self basicNew testOrderedSet01
|
|
584 |
"
|
301
|
585 |
!
|
|
586 |
|
|
587 |
testOrderedSet02
|
|
588 |
|col|
|
|
589 |
|
|
590 |
col := OrderedSet new.
|
|
591 |
|
|
592 |
col add:'a'.
|
|
593 |
col add:'b'.
|
|
594 |
col add:'c'.
|
|
595 |
self assert:( col size == 3 ).
|
|
596 |
self assert:( Array streamContents:[:s |
|
|
597 |
col do:[:each | s nextPut:each]
|
|
598 |
]
|
|
599 |
) = #('a' 'b' 'c' ).
|
|
600 |
|
|
601 |
"
|
|
602 |
self new testOrderedSet02
|
|
603 |
"
|
|
604 |
!
|
|
605 |
|
|
606 |
testOrderedSet03
|
|
607 |
|col|
|
|
608 |
|
|
609 |
col := OrderedSet new.
|
|
610 |
|
|
611 |
col add:'a'.
|
|
612 |
col add:'b'.
|
|
613 |
col add:'c'.
|
|
614 |
col add:'a'.
|
|
615 |
col add:'b'.
|
|
616 |
self assert:( col size == 3 ).
|
|
617 |
self assert:( Array streamContents:[:s |
|
|
618 |
col do:[:each | s nextPut:each]
|
|
619 |
]
|
|
620 |
) = #('a' 'b' 'c' ).
|
|
621 |
|
|
622 |
"
|
|
623 |
self new testOrderedSet03
|
|
624 |
"
|
|
625 |
!
|
|
626 |
|
|
627 |
testOrderedSet04
|
|
628 |
|col|
|
|
629 |
|
|
630 |
col := OrderedSet new.
|
|
631 |
|
|
632 |
col add:'a'.
|
|
633 |
col addFirst:'b'.
|
|
634 |
col addFirst:'c'.
|
|
635 |
self assert:( col size == 3 ).
|
|
636 |
self assert:( Array streamContents:[:s |
|
|
637 |
col do:[:each | s nextPut:each]
|
|
638 |
]
|
|
639 |
) = #('c' 'b' 'a' ).
|
|
640 |
|
|
641 |
"
|
|
642 |
self new testOrderedSet04
|
|
643 |
"
|
|
644 |
!
|
|
645 |
|
|
646 |
testOrderedSet05
|
|
647 |
|col|
|
|
648 |
|
|
649 |
col := OrderedSet new.
|
|
650 |
|
|
651 |
col add:'a'.
|
|
652 |
col addFirst:'b'.
|
|
653 |
col addFirst:'c'.
|
|
654 |
col add:'a'.
|
|
655 |
col add:'b'.
|
|
656 |
col add:'c'.
|
|
657 |
self assert:( col size == 3 ).
|
|
658 |
self assert:( Array streamContents:[:s |
|
|
659 |
col do:[:each | s nextPut:each]
|
|
660 |
]
|
|
661 |
) = #('c' 'b' 'a' ).
|
|
662 |
|
|
663 |
"
|
|
664 |
self new testOrderedSet05
|
|
665 |
"
|
264
|
666 |
! !
|
|
667 |
|
297
|
668 |
!CollectionTests methodsFor:'tests-replace'!
|
|
669 |
|
|
670 |
testEmptyReplace
|
|
671 |
| array1 array2 |
|
|
672 |
|
|
673 |
array1 := Array with: 1 with: 2 with: 3 with: 4.
|
|
674 |
array2 := Array with: 5 with: 6 with: 7.
|
|
675 |
|
|
676 |
array1 replaceFrom:1 to:0 with:array2 startingAt:1.
|
|
677 |
|
|
678 |
self should: [ array1 = #(1 2 3 4) ].
|
|
679 |
|
|
680 |
"
|
|
681 |
self new testEmptyReplace
|
|
682 |
"
|
538
|
683 |
!
|
|
684 |
|
|
685 |
testTransliterating
|
|
686 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'b-g' to:'B-G' ) = 'aBCDEFGhijkl1234567890'.
|
|
687 |
self assert:( 'abcdefghij-kl1234567890' copyTransliterating:'b\-g' to:'B+G' ) = 'aBcdefGhij+kl1234567890'.
|
|
688 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'69' to:'96' ) = 'abcdefghijkl1234597860' .
|
|
689 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'a' to:'b' ) = 'bbcdefghijkl1234567890' .
|
|
690 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'aeiou' to:'AEIOU' ) = 'AbcdEfghIjkl1234567890'.
|
|
691 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'QERTYUIOPX' ) = 'abcdefghijklERTYUIOPXQ' .
|
|
692 |
|
|
693 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'A' complement:false squashDuplicates:false )
|
|
694 |
= 'abcdefghijklAAAAAAAAAA'.
|
|
695 |
|
|
696 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'A' complement:false squashDuplicates:true )
|
|
697 |
= 'abcdefghijklA'.
|
|
698 |
|
|
699 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'*' complement:false squashDuplicates:false )
|
|
700 |
= 'abcdefghijkl**********'.
|
|
701 |
|
|
702 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'*' complement:true squashDuplicates:false )
|
|
703 |
= '************1234567890'.
|
|
704 |
|
|
705 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'a-zA-Z' to:' ' complement:true squashDuplicates:false )
|
|
706 |
= 'abcdefghijkl '.
|
|
707 |
|
|
708 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'a-zA-Z' to:' ' complement:false squashDuplicates:false )
|
|
709 |
= ' 1234567890'.
|
|
710 |
|
|
711 |
self assert:( 'abcdefghijkl1234567890abcdefghijkl' copyTransliterating:'a-zA-Z' to:'' complement:false squashDuplicates:false )
|
|
712 |
= '1234567890'.
|
|
713 |
|
|
714 |
self assert:( 'abcdefghijkl1234567890abcdefghijkl' copyTransliterating:'a-zA-Z' to:'' complement:true squashDuplicates:false )
|
|
715 |
= 'abcdefghijklabcdefghijkl'.
|
297
|
716 |
! !
|
|
717 |
|
639
|
718 |
!CollectionTests methodsFor:'tests-searching'!
|
|
719 |
|
|
720 |
test_min_max
|
|
721 |
|a|
|
|
722 |
|
|
723 |
#(
|
|
724 |
asArray
|
|
725 |
asFloatArray
|
|
726 |
asDoubleArray
|
|
727 |
asSignedIntegerArray
|
|
728 |
) do:[:converter |
|
640
|
729 |
|empty|
|
|
730 |
|
|
731 |
empty := #() perform:converter.
|
|
732 |
self should:[ empty min ] raise:Error.
|
|
733 |
self should:[ empty max ] raise:Error.
|
|
734 |
self should:[ empty minMax ] raise:Error.
|
|
735 |
|
639
|
736 |
#(
|
640
|
737 |
(0 0)
|
|
738 |
(1 1)
|
|
739 |
(-1 -1)
|
|
740 |
(0 1)
|
|
741 |
(1 2)
|
|
742 |
(-1 -0)
|
|
743 |
(-1 1)
|
639
|
744 |
(1 10000)
|
|
745 |
(1 10001)
|
|
746 |
(2 10000)
|
|
747 |
(2 10001)
|
|
748 |
(-1000 1000)
|
|
749 |
(-1000 999)
|
|
750 |
) pairsDo:[:min :max |
|
|
751 |
a := (min to:max) perform:converter.
|
|
752 |
self assert:(a min) = min.
|
|
753 |
self assert:(a max) = max.
|
|
754 |
self assert:(a minMax) = { min. max }.
|
|
755 |
|
|
756 |
a := a reverse.
|
|
757 |
self assert:(a min) = min.
|
|
758 |
self assert:(a max) = max.
|
|
759 |
self assert:(a minMax) = { min. max }.
|
|
760 |
|
|
761 |
a := a randomShuffle.
|
|
762 |
self assert:(a min) = min.
|
|
763 |
self assert:(a max) = max.
|
|
764 |
self assert:(a minMax) = { min. max }.
|
|
765 |
].
|
|
766 |
].
|
|
767 |
|
|
768 |
"Created: / 07-10-2011 / 13:11:36 / cg"
|
|
769 |
! !
|
|
770 |
|
264
|
771 |
!CollectionTests methodsFor:'tests-sorting'!
|
212
|
772 |
|
|
773 |
testSort01
|
|
774 |
| col errs last |
|
|
775 |
|
|
776 |
col := SortedCollection new addAll: (100 to: 1 by: -1); yourself.
|
|
777 |
last := nil.
|
|
778 |
errs := col inject: 0 into:
|
|
779 |
[ :totIn :n | |totOut|
|
|
780 |
|
|
781 |
totOut := totIn.
|
|
782 |
last notNil ifTrue: [ last > n ifTrue: [ totOut := totOut + 1 ] ].
|
|
783 |
last := n.
|
|
784 |
totOut ].
|
|
785 |
self should: [ errs = 0 ]
|
|
786 |
|
|
787 |
"
|
|
788 |
self basicNew testSort01
|
|
789 |
"
|
|
790 |
!
|
|
791 |
|
|
792 |
testSortStability01
|
|
793 |
"Verify that the sort is stable"
|
|
794 |
|
|
795 |
| testData col lastTestData errs |
|
|
796 |
|
|
797 |
testData := OrderedCollection new.
|
|
798 |
testData addAll: ((100 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]).
|
|
799 |
testData addAll: ((100 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]).
|
|
800 |
testData addAll: ((100 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]).
|
|
801 |
1 to: testData size do: [ :i | (testData at: i) order: i ].
|
|
802 |
|
|
803 |
col := (SortedCollection new sortBlock: [ :v1 :v2 | v1 value <= v2 value ]) addAll: testData.
|
|
804 |
lastTestData := nil.
|
|
805 |
|
|
806 |
errs := col inject: 0 into:
|
|
807 |
[ :totIn :aSortTestData | |totOut|
|
|
808 |
totOut := totIn.
|
|
809 |
lastTestData notNil ifTrue:
|
|
810 |
[ lastTestData value = aSortTestData value ifTrue:
|
|
811 |
[ lastTestData order > aSortTestData order ifTrue: [ totOut := totOut + 1 ] ] ].
|
|
812 |
lastTestData := aSortTestData.
|
|
813 |
totOut ].
|
|
814 |
self should: [ errs = 0 ]
|
|
815 |
|
|
816 |
"
|
|
817 |
self basicNew testSortStability01
|
|
818 |
"
|
|
819 |
!
|
|
820 |
|
|
821 |
testSortStability02
|
|
822 |
"Verify that the sort is stable"
|
|
823 |
|
|
824 |
| testData col lastTestData errs |
|
|
825 |
|
|
826 |
testData := OrderedCollection new.
|
|
827 |
(25 to: 1 by: -1) do: [ :i | 1 to: 100 do: [ :j | testData add: (SortTestData new value: i ) ] ].
|
|
828 |
1 to: testData size do: [ :i | (testData at: i) order: i ].
|
|
829 |
|
|
830 |
col := (SortedCollection new sortBlock: [ :v1 :v2 | v1 value <= v2 value ]) addAll: testData.
|
|
831 |
lastTestData := nil.
|
|
832 |
|
|
833 |
errs := col inject: 0 into:
|
|
834 |
[ :totIn :aSortTestData | |totOut|
|
|
835 |
totOut := totIn.
|
|
836 |
lastTestData notNil ifTrue:
|
|
837 |
[ lastTestData value = aSortTestData value ifTrue:
|
|
838 |
[ lastTestData order > aSortTestData order ifTrue: [ totOut := totOut + 1 ] ] ].
|
|
839 |
lastTestData := aSortTestData.
|
|
840 |
totOut ].
|
|
841 |
self should: [ errs = 0 ]
|
|
842 |
|
|
843 |
"
|
|
844 |
self basicNew testSortStability02
|
|
845 |
"
|
|
846 |
! !
|
|
847 |
|
293
|
848 |
!CollectionTests methodsFor:'tests-squeak'!
|
|
849 |
|
|
850 |
testIfEmptyifNotEmpty
|
|
851 |
self assert: (empty ifEmpty: [true] ifNotEmpty: [false]).
|
|
852 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [true]).
|
|
853 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [:s | s first = #x])
|
|
854 |
!
|
|
855 |
|
|
856 |
testIfEmptyifNotEmptyDo
|
|
857 |
self assert: (empty ifEmpty: [true] ifNotEmptyDo: [:s | false]).
|
|
858 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmptyDo: [:s | s first = #x])
|
|
859 |
!
|
|
860 |
|
|
861 |
testIfNotEmpty
|
|
862 |
empty ifNotEmpty: [self assert: false].
|
|
863 |
self assert: (nonEmpty ifNotEmpty: [self]) == self.
|
|
864 |
self assert: (nonEmpty ifNotEmpty: [:s | s first]) = #x
|
|
865 |
!
|
|
866 |
|
|
867 |
testIfNotEmptyDo
|
|
868 |
empty ifNotEmptyDo: [:s | self assert: false].
|
|
869 |
self assert: (nonEmpty ifNotEmptyDo: [:s | s first]) = #x
|
|
870 |
!
|
|
871 |
|
|
872 |
testIfNotEmptyDoifNotEmpty
|
|
873 |
self assert: (empty ifNotEmptyDo: [:s | false] ifEmpty: [true]).
|
|
874 |
self assert: (nonEmpty ifNotEmptyDo: [:s | s first = #x] ifEmpty: [false])
|
|
875 |
!
|
|
876 |
|
|
877 |
testIfNotEmptyifEmpty
|
|
878 |
self assert: (empty ifEmpty: [true] ifNotEmpty: [false]).
|
|
879 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [true]).
|
|
880 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [:s | s first = #x])
|
|
881 |
! !
|
|
882 |
|
212
|
883 |
!CollectionTests::SortTestData methodsFor:'accessing'!
|
|
884 |
|
|
885 |
value
|
|
886 |
"Answer the value of the receiver's ''value'' instance variable."
|
|
887 |
|
|
888 |
^value
|
|
889 |
!
|
|
890 |
|
|
891 |
value: anObject
|
|
892 |
"Set the value of the receiver's ''value'' instance variable to the argument, anObject."
|
|
893 |
|
|
894 |
value := anObject
|
|
895 |
! !
|
|
896 |
|
|
897 |
!CollectionTests::SortTestData methodsFor:'order'!
|
|
898 |
|
|
899 |
order
|
|
900 |
"Answer the value of the receiver's ''order'' instance variable."
|
|
901 |
|
|
902 |
^order
|
|
903 |
!
|
|
904 |
|
|
905 |
order: anObject
|
|
906 |
"Set the value of the receiver's ''order'' instance variable to the argument, anObject."
|
|
907 |
|
|
908 |
order := anObject
|
|
909 |
! !
|
|
910 |
|
|
911 |
!CollectionTests::SortTestData methodsFor:'printing & storing'!
|
|
912 |
|
|
913 |
printOn: aStream
|
|
914 |
super printOn: aStream.
|
|
915 |
aStream
|
|
916 |
nextPutAll: '(value: ';
|
|
917 |
nextPutAll: value printString;
|
|
918 |
nextPutAll: ' order: ';
|
|
919 |
nextPutAll: order printString;
|
|
920 |
nextPut: $)
|
115
|
921 |
! !
|
|
922 |
|
|
923 |
!CollectionTests class methodsFor:'documentation'!
|
|
924 |
|
|
925 |
version
|
|
926 |
^ '$Header$'
|
640
|
927 |
!
|
|
928 |
|
|
929 |
version_CVS
|
|
930 |
^ '$Header$'
|
115
|
931 |
! !
|