author | Claus Gittinger <cg@exept.de> |
Tue, 04 Feb 2014 20:26:19 +0100 | |
changeset 1041 | 6692cfae6a25 |
parent 1040 | 35d20906f91c |
child 1043 | b95983db1639 |
permissions | -rw-r--r-- |
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 |
||
655 | 46 |
checkSorted:aSortedCollection with:sortBlock against:anOriginalCollection |
47 |
|first| |
|
48 |
||
49 |
self assert:aSortedCollection size = anOriginalCollection size. |
|
50 |
||
51 |
"is it sorted?" |
|
52 |
first := true. |
|
53 |
aSortedCollection inject:nil into:[:last :each| |
|
54 |
first ifTrue:[first := false] |
|
55 |
ifFalse:[self assert:(sortBlock value:last value:each)]. each]. |
|
56 |
||
57 |
"same elements as in original?" |
|
58 |
self assert:(aSortedCollection asBag = anOriginalCollection asBag). |
|
59 |
! |
|
60 |
||
301 | 61 |
collectedDoArgsOf:aCollection |
62 |
|collectedDoArgs| |
|
63 |
||
64 |
collectedDoArgs := OrderedCollection new. |
|
65 |
aCollection do:[:each | collectedDoArgs add:each]. |
|
66 |
^ collectedDoArgs |
|
67 |
! ! |
|
68 |
||
293 | 69 |
!CollectionTests methodsFor:'initialize-release'! |
70 |
||
71 |
setUp |
|
295 | 72 |
empty := Set new. |
73 |
nonEmpty := OrderedCollection with: #x. |
|
293 | 74 |
! ! |
75 |
||
264 | 76 |
!CollectionTests methodsFor:'tests-dictionary'! |
115 | 77 |
|
78 |
testDictionary01 |
|
301 | 79 |
|d v1 v2 v3 ret| |
115 | 80 |
|
81 |
d := Dictionary new. |
|
82 |
d at:1 put:(v1 := 'one'). |
|
83 |
d at:2 put:(v2 := 'two'). |
|
84 |
d at:3 put:(v3 := 'three'). |
|
85 |
||
86 |
self assert: ( d size == 3 ). |
|
301 | 87 |
|
757
2d776bef407b
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
677
diff
changeset
|
88 |
self assert:(ret := self collectedDoArgsOf:d) asSet = #('one' 'two' 'three') asSet. |
301 | 89 |
self assert:(ret := d collect:[:each | each]) = #('one' 'two' 'three') asBag. |
90 |
self assert:(ret := d select:[:each | true]) = (Dictionary withAssociations:(Array with:(1->'one') with:(2->'two') with:(3->'three'))). |
|
91 |
||
115 | 92 |
self assert: ( (d at:1) == v1 ). |
93 |
self assert: ( (d at:2) == v2 ). |
|
94 |
self assert: ( (d at:3) == v3 ). |
|
95 |
||
96 |
d at:3 put:(v3 := 'drei'). |
|
97 |
||
98 |
self assert: ( d size == 3 ). |
|
99 |
||
100 |
self assert: ( (d at:1) == v1 ). |
|
101 |
self assert: ( (d at:2) == v2 ). |
|
102 |
self assert: ( (d at:3) == v3 ). |
|
103 |
||
104 |
self assert: ( (d keyAtValue:v1) = 1 ). |
|
105 |
||
106 |
" |
|
107 |
self basicNew testDictionary01 |
|
108 |
" |
|
585 | 109 |
|
110 |
"Modified: / 04-07-2011 / 19:28:39 / cg" |
|
264 | 111 |
! ! |
112 |
||
113 |
!CollectionTests methodsFor:'tests-general'! |
|
114 |
||
615 | 115 |
doTestDictionaryLikeAddRemoveOperationsIn:aClass |
116 |
|coll| |
|
117 |
||
118 |
coll := aClass new. |
|
119 |
||
120 |
self assert: ( coll size == 0 ). |
|
121 |
self assert: ( coll isEmpty ). |
|
122 |
self assert: ( coll notEmpty not ). |
|
123 |
self assert: ( coll isEmptyOrNil ). |
|
124 |
self assert: ( coll notEmptyOrNil not ). |
|
125 |
||
126 |
coll at:1 put:'one'. |
|
127 |
||
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 at:2 put:'two'. |
|
135 |
||
136 |
self assert: ( coll size == 2 ). |
|
137 |
self assert: ( coll isEmpty not). |
|
138 |
self assert: ( coll notEmpty ). |
|
139 |
self assert: ( coll isEmptyOrNil not ). |
|
140 |
self assert: ( coll notEmptyOrNil ). |
|
141 |
||
142 |
coll removeKey:2. |
|
143 |
self assert: ( coll size == 1 ). |
|
144 |
self assert: ( coll isEmpty not). |
|
145 |
self assert: ( coll notEmpty ). |
|
146 |
self assert: ( coll isEmptyOrNil not ). |
|
147 |
self assert: ( coll notEmptyOrNil ). |
|
148 |
||
149 |
coll removeKey:1. |
|
150 |
self assert: ( coll size == 0 ). |
|
151 |
self assert: ( coll isEmpty ). |
|
152 |
self assert: ( coll notEmpty not ). |
|
153 |
self assert: ( coll isEmptyOrNil ). |
|
154 |
self assert: ( coll notEmptyOrNil not ). |
|
155 |
||
156 |
" |
|
157 |
self basicNew doTestDictionaryLikeAddRemoveOperations |
|
158 |
" |
|
159 |
||
160 |
"Created: / 08-08-2011 / 16:01:14 / cg" |
|
161 |
! |
|
162 |
||
163 |
doTestGeneralAddRemoveOperationsIn:aClass |
|
164 |
|coll| |
|
165 |
||
166 |
coll := aClass new. |
|
167 |
||
168 |
self assert: ( coll size == 0 ). |
|
169 |
self assert: ( coll isEmpty ). |
|
170 |
self assert: ( coll notEmpty not ). |
|
171 |
self assert: ( coll isEmptyOrNil ). |
|
172 |
self assert: ( coll notEmptyOrNil not ). |
|
173 |
||
174 |
coll add:1. |
|
175 |
||
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 add:2. |
|
183 |
||
184 |
self assert: ( coll size == 2 ). |
|
185 |
self assert: ( coll isEmpty not). |
|
186 |
self assert: ( coll notEmpty ). |
|
187 |
self assert: ( coll isEmptyOrNil not ). |
|
188 |
self assert: ( coll notEmptyOrNil ). |
|
189 |
||
190 |
coll remove:2. |
|
191 |
self assert: ( coll size == 1 ). |
|
192 |
self assert: ( coll isEmpty not). |
|
193 |
self assert: ( coll notEmpty ). |
|
194 |
self assert: ( coll isEmptyOrNil not ). |
|
195 |
self assert: ( coll notEmptyOrNil ). |
|
196 |
||
197 |
coll remove:1. |
|
198 |
self assert: ( coll size == 0 ). |
|
199 |
self assert: ( coll isEmpty ). |
|
200 |
self assert: ( coll notEmpty not ). |
|
201 |
self assert: ( coll isEmptyOrNil ). |
|
202 |
self assert: ( coll notEmptyOrNil not ). |
|
203 |
||
204 |
" |
|
205 |
self basicNew testGeneralOperations |
|
206 |
" |
|
207 |
||
208 |
"Created: / 08-08-2011 / 16:00:06 / cg" |
|
209 |
! |
|
210 |
||
264 | 211 |
doTestGeneralCollectionOperationsIn:aClass |
212 |
|coll| |
|
213 |
||
214 |
coll := aClass new. |
|
215 |
||
216 |
self assert: ( coll size == 0 ). |
|
217 |
self assert: ( coll isEmpty ). |
|
218 |
self assert: ( coll notEmpty not ). |
|
219 |
self assert: ( coll isEmptyOrNil ). |
|
220 |
self assert: ( coll notEmptyOrNil not ). |
|
221 |
||
222 |
self should: [ coll first ] raise:Error. |
|
223 |
self should: [ coll last ] raise:Error. |
|
224 |
self should: [ (coll at:1) ] raise:Error. |
|
225 |
||
226 |
self assert: ( (coll includes:0) not ). |
|
227 |
||
228 |
" |
|
229 |
self basicNew testGeneralOperations |
|
230 |
" |
|
156 | 231 |
! |
232 |
||
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
233 |
doTestSequentialCollectionOperationsIn:aClass |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
234 |
|coll1 coll2| |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
235 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
236 |
coll1 := self protoCollectionFor: aClass. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
237 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
238 |
self assert: ( coll1 size > 0 ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
239 |
self assert: ( coll1 isEmpty not ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
240 |
self assert: ( coll1 notEmpty ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
241 |
self assert: ( coll1 isEmptyOrNil not ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
242 |
self assert: ( coll1 notEmptyOrNil ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
243 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
244 |
self assert: ( coll1 first = (coll1 at:1) ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
245 |
self assert: ( coll1 last = (coll1 at:(coll1 size)) ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
246 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
247 |
self assert: ( coll1 = coll1 ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
248 |
self assert: ( coll1 ~= coll1 ) not. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
249 |
coll2 := coll1 copy. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
250 |
self assert: ( coll2 = coll1 ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
251 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
252 |
coll2 replaceFrom:1 to:coll2 size with:coll1 startingAt:1. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
253 |
self assert: ( coll2 = coll1 ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
254 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
255 |
"overlapping copy" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
256 |
coll2 replaceFrom:2 to:coll2 size with:coll2 startingAt:1. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
257 |
coll2 replaceFrom:1 to:coll2 size-1 with:coll2 startingAt:2. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
258 |
coll2 at:(coll2 size) put:(coll1 at:coll1 size). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
259 |
self assert: ( coll2 = coll1 ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
260 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
261 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
262 |
self basicNew testSequentialCollectionOperations |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
263 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
264 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
265 |
"Created: / 08-05-2012 / 10:50:08 / cg" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
266 |
! |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
267 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
268 |
protoCollectionFor: aClass |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
269 |
aClass == BooleanArray ifTrue: [ |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
270 |
^ BooleanArray withAll:#(true false true true false false true false false true) |
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
271 |
]. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
272 |
aClass == BitArray ifTrue: [ |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
273 |
^ BitArray withAll:#(1 0 1 1 0 0 1 0 0 1) |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
274 |
]. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
275 |
aClass == ByteArray ifTrue: [ |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
276 |
^ ByteArray withAll:#(1 2 3 4 16rFC 16rFD 16rFE 16rFF) |
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
277 |
]. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
278 |
aClass == String ifTrue: [ |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
279 |
^ 'abcdefghijklmnopqrstuvwxyz' |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
280 |
]. |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
281 |
(aClass includesBehavior:CharacterArray) ifTrue:[ |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
282 |
^ 'abcdefghijklmnopqrstuvwxyz' as: aClass |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
283 |
]. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
284 |
(aClass includesBehavior:AbstractNumberVector) ifTrue:[ |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
285 |
(aClass includesBehavior:UnboxedIntegerArray) ifTrue:[ |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
286 |
^ #(1 2 3 4 5 6 7 8 9 10) as: aClass |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
287 |
]. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
288 |
^ #(1.0 2 3.0 4 5.0 6 7.0 8 9.0 10) as: aClass |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
289 |
]. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
290 |
^ #(1 true 2.0 false 3 nil 4.0 5 6.0 7 8.0 9 10.0) as: aClass |
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
291 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
292 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
293 |
self basicNew testSequentialCollectionOperations |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
294 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
295 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
296 |
"Created: / 08-05-2012 / 10:50:50 / cg" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
297 |
! |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
298 |
|
615 | 299 |
testDictionaryLikeAddRemoveOperations |
300 |
|classes| |
|
301 |
||
302 |
classes := OrderedCollection new. |
|
303 |
classes |
|
304 |
add:Dictionary; |
|
305 |
add:IdentityDictionary; |
|
306 |
add:OrderedDictionary; |
|
307 |
add:BTree. |
|
308 |
||
309 |
classes do:[:eachClass | |
|
310 |
self doTestDictionaryLikeAddRemoveOperationsIn:eachClass |
|
311 |
]. |
|
312 |
||
313 |
" |
|
314 |
self basicNew testDictionaryLikeAddRemoveOperations |
|
315 |
" |
|
316 |
||
317 |
"Created: / 08-08-2011 / 15:59:52 / cg" |
|
318 |
! |
|
319 |
||
320 |
testGeneralAddRemoveOperations |
|
321 |
|classes| |
|
322 |
||
323 |
classes := OrderedCollection new. |
|
324 |
classes |
|
325 |
"/ add:RunArray; |
|
326 |
add:Bag; |
|
327 |
add:Set; |
|
328 |
add:IdentitySet; |
|
329 |
"/add:Dictionary; |
|
330 |
"/add:IdentityDictionary; |
|
331 |
add:OrderedCollection; |
|
332 |
add:SortedCollection; |
|
333 |
"/add:Queue; |
|
334 |
"/add:Stack; |
|
335 |
add:SortedCollection; |
|
336 |
"/add:OrderedDictionary; |
|
337 |
add:OrderedSet. |
|
338 |
"/add:BTree. |
|
339 |
||
340 |
classes do:[:eachClass | |
|
341 |
self doTestGeneralAddRemoveOperationsIn:eachClass |
|
342 |
]. |
|
343 |
||
344 |
" |
|
345 |
self basicNew testGeneralAddRemoveOperations |
|
346 |
" |
|
347 |
||
348 |
"Created: / 08-08-2011 / 15:59:02 / cg" |
|
349 |
! |
|
350 |
||
264 | 351 |
testGeneralOperations |
352 |
|classes| |
|
353 |
||
354 |
classes := OrderedCollection new. |
|
355 |
classes |
|
356 |
add:RunArray; |
|
357 |
add:Bag; |
|
358 |
add:Set; |
|
359 |
add:IdentitySet; |
|
360 |
add:Dictionary; |
|
361 |
add:IdentityDictionary; |
|
362 |
add:OrderedCollection; |
|
363 |
add:SortedCollection; |
|
364 |
add:Queue; |
|
365 |
add:Stack; |
|
366 |
add:SortedCollection; |
|
367 |
add:OrderedDictionary; |
|
615 | 368 |
add:OrderedSet; |
369 |
add:BTree. |
|
264 | 370 |
|
371 |
classes do:[:eachClass | |
|
372 |
self doTestGeneralCollectionOperationsIn:eachClass |
|
373 |
]. |
|
374 |
||
375 |
" |
|
376 |
self basicNew testGeneralOperations |
|
377 |
" |
|
615 | 378 |
|
379 |
"Modified: / 08-08-2011 / 15:53:16 / cg" |
|
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
380 |
! |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
381 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
382 |
testSequentialCollectionOperations |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
383 |
|classes| |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
384 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
385 |
classes := OrderedCollection new. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
386 |
classes |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
387 |
add:OrderedCollection; |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
388 |
add:Array; |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
389 |
add:String; |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
390 |
add:ByteArray; |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
391 |
add:WordArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
392 |
add:IntegerArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
393 |
add:LongIntegerArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
394 |
add:SignedWordArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
395 |
add:SignedIntegerArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
396 |
add:SignedLongIntegerArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
397 |
add:FloatArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
398 |
add:DoubleArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
399 |
add:HalfFloatArray; |
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
400 |
add:TwoByteString; |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
401 |
add:Unicode16String; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
402 |
add:Unicode32String; |
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
403 |
add:BooleanArray; |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
404 |
add:BitArray. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
405 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
406 |
classes do:[:eachClass | |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
407 |
self doTestSequentialCollectionOperationsIn:eachClass |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
408 |
]. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
409 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
410 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
411 |
self basicNew testSequentialCollectionOperations |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
412 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
413 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
414 |
"Created: / 08-05-2012 / 10:48:40 / cg" |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
415 |
! |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
416 |
|
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
417 |
testSpecialArrayClasses |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
418 |
|a| |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
419 |
|
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
420 |
a := #(1 2 3 4 5) asWordArray. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
421 |
self assert:(a at:1) == 1. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
422 |
self assert:(a at:a size) == 5. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
423 |
self assert:(a first) == 1. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
424 |
self assert:(a last) == 5. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
425 |
|
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
426 |
a := #(1 2 3 4 5) asIntegerArray. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
427 |
self assert:(a at:1) == 1. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
428 |
self assert:(a at:a size) == 5. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
429 |
self assert:(a first) == 1. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
430 |
self assert:(a last) == 5. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
431 |
|
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
432 |
a := #(1 2 3 4 5) asLongIntegerArray. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
433 |
self assert:(a at:1) == 1. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
434 |
self assert:(a at:a size) == 5. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
435 |
self assert:(a first) == 1. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
436 |
self assert:(a last) == 5. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
437 |
|
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
438 |
" |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
439 |
self basicNew testSpecialArrayClasses |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
440 |
" |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
441 |
|
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
442 |
"Created: / 08-05-2012 / 10:48:40 / cg" |
1041
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
443 |
! |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
444 |
|
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
445 |
testSpecialArrayClasses2 |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
446 |
|a| |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
447 |
|
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
448 |
a := #(1 2 3 4 5) asFloatArray. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
449 |
self assert:(a at:1) = 1.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
450 |
self assert:(a at:a size) = 5.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
451 |
self assert:(a first) = 1.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
452 |
self assert:(a last) = 5.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
453 |
|
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
454 |
a := #(1 2 3 4 5) asDoubleArray. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
455 |
self assert:(a at:1) = 1.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
456 |
self assert:(a at:a size) = 5.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
457 |
self assert:(a first) = 1.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
458 |
self assert:(a last) = 5.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
459 |
|
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
460 |
a := #(1 2 3 4 5) asHalfFloatArray. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
461 |
self assert:(a at:1) = 1.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
462 |
self assert:(a at:a size) = 5.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
463 |
self assert:(a first) = 1.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
464 |
self assert:(a last) = 5.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
465 |
|
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
466 |
" |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
467 |
self basicNew testSpecialArrayClasses2 |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
468 |
" |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
469 |
|
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
470 |
"Created: / 08-05-2012 / 10:48:40 / cg" |
264 | 471 |
! ! |
472 |
||
473 |
!CollectionTests methodsFor:'tests-interval'! |
|
474 |
||
162 | 475 |
testInterval01 |
663
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
476 |
|i1 i2 enumeratedValues| |
162 | 477 |
|
644 | 478 |
i1 := 1 to:10. |
162 | 479 |
|
644 | 480 |
self assert: ( i1 size == 10 ). |
162 | 481 |
|
644 | 482 |
self assert: ( i1 includes:1 ). |
483 |
self assert: ( i1 includes:10 ). |
|
162 | 484 |
|
644 | 485 |
self assert: ( i1 min == 1 ). |
486 |
self assert: ( i1 max == 10 ). |
|
162 | 487 |
|
488 |
"cannot add/remove" |
|
644 | 489 |
self should:[i1 add:99] raise:Error. |
490 |
self should:[i1 remove:10] raise:Error. |
|
491 |
||
492 |
i2 := 2 to:20 by:2. |
|
493 |
self assert: ( i2 size == 10 ). |
|
494 |
||
495 |
self assert: ( i2 includes:0 ) not. |
|
496 |
self assert: ( i2 includes:1 ) not. |
|
497 |
self assert: ( i2 includes:2 ). |
|
498 |
self assert: ( i2 includes:3 ) not. |
|
499 |
self assert: ( i2 includes:10 ). |
|
500 |
self assert: ( i2 includes:19 ) not. |
|
501 |
self assert: ( i2 includes:20 ). |
|
502 |
self assert: ( i2 includes:21 ) not. |
|
503 |
self assert: ( i2 includes:22 ) not. |
|
504 |
||
505 |
self assert: ( i2 min == 2 ). |
|
506 |
self assert: ( i2 max == 20 ). |
|
507 |
||
508 |
self assert: ( i2 keys asArray = (1 to:10) asArray ). |
|
162 | 509 |
|
663
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
510 |
enumeratedValues := OrderedCollection new. |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
511 |
i1 do:[:each | enumeratedValues add:each ]. |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
512 |
self assert:(enumeratedValues size == 10). |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
513 |
self assert:(enumeratedValues asArray = #(1 2 3 4 5 6 7 8 9 10)). |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
514 |
|
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
515 |
enumeratedValues := OrderedCollection new. |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
516 |
i2 do:[:each | enumeratedValues add:each ]. |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
517 |
self assert:(enumeratedValues size == 10). |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
518 |
self assert:(enumeratedValues asArray = #(2 4 6 8 10 12 14 16 18 20)). |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
519 |
|
666 | 520 |
self assert: (i1 collect:[:el | el even]) asArray = #(false true false true false true false true false true). |
521 |
self assert: (i2 collect:[:el | el even]) asArray = #(true true true true true true true true true true). |
|
664 | 522 |
|
162 | 523 |
" |
524 |
self basicNew testInterval01 |
|
525 |
" |
|
644 | 526 |
|
664 | 527 |
"Modified: / 03-05-2012 / 18:36:41 / cg" |
264 | 528 |
! ! |
529 |
||
301 | 530 |
!CollectionTests methodsFor:'tests-orderedCollection'! |
531 |
||
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
532 |
testMergeSortStability01 |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
533 |
"Verify that the sort is stable" |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
534 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
535 |
| testData lastTestData errs col| |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
536 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
537 |
testData := OrderedCollection new. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
538 |
testData addAll: ((100 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]). |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
539 |
testData addAll: ((100 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]). |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
540 |
testData addAll: ((100 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]). |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
541 |
testData keysAndValuesDo:[:idx :each| each order: idx ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
542 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
543 |
col := testData copy. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
544 |
col mergeSort:[:v1 :v2 | v1 value < v2 value ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
545 |
self checkSorted:col with:[:v1 :v2 | v1 value <= v2 value ] against:testData. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
546 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
547 |
lastTestData := nil. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
548 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
549 |
errs := col inject: 0 into: |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
550 |
[ :totIn :aSortTestData | |totOut| |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
551 |
totOut := totIn. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
552 |
lastTestData notNil ifTrue: |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
553 |
[ lastTestData value = aSortTestData value ifTrue: |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
554 |
[ lastTestData order > aSortTestData order ifTrue: [ totOut := totOut + 1 ] ] ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
555 |
lastTestData := aSortTestData. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
556 |
totOut ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
557 |
self should: [ errs = 0 ] |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
558 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
559 |
" |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
560 |
self basicNew testMergeSortStability01 |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
561 |
" |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
562 |
! |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
563 |
|
301 | 564 |
testOrderedCollection01_Sort1 |
565 |
|col col2| |
|
566 |
||
567 |
col := #( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ) copy. |
|
568 |
col sort. |
|
585 | 569 |
self assert:( col sameContentsAs: (1 to:20)). |
301 | 570 |
|
571 |
col := #( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ) copy reverse. |
|
572 |
col sort. |
|
585 | 573 |
self assert:( col sameContentsAs: (1 to:20) ). |
301 | 574 |
|
575 |
col := #( 10 2 13 4 15 6 17 8 19 11 1 12 3 14 5 16 7 18 9 20 ) copy. |
|
576 |
col sort. |
|
585 | 577 |
self assert:( col sameContentsAs: (1 to:20) ). |
301 | 578 |
|
579 |
col := ( 1 to: 10000 ) asOrderedCollection. |
|
580 |
col sort. |
|
585 | 581 |
self assert:( col sameContentsAs: (1 to:10000) ). |
301 | 582 |
|
583 |
col := ( 1 to: 10000 ) asOrderedCollection. |
|
584 |
col2 := ( 1 to: 10000 ) asOrderedCollection. |
|
585 |
col sortWith:col2. |
|
585 | 586 |
self assert:( col sameContentsAs: (1 to:10000) ). |
587 |
self assert:( col2 sameContentsAs: (1 to:10000) ). |
|
301 | 588 |
|
589 |
col := ( 10000 to: 1 by:-1) asOrderedCollection. |
|
590 |
col2 := ( 10000 to: 1 by:-1) asOrderedCollection. |
|
591 |
col sortWith:col2. |
|
585 | 592 |
self assert:( col sameContentsAs: (1 to:10000) ). |
593 |
self assert:( col2 sameContentsAs: (1 to:10000) ). |
|
301 | 594 |
|
595 |
" |
|
596 |
self new testOrderedCollection01_Sort1 |
|
597 |
" |
|
585 | 598 |
|
599 |
"Modified: / 04-07-2011 / 19:29:54 / cg" |
|
301 | 600 |
! |
601 |
||
602 |
testOrderedCollection02_SortBigCollection |
|
603 |
| size col sortBlock| |
|
604 |
||
605 |
size := 12500. |
|
606 |
col := OrderedCollection new. |
|
607 |
1 to:size do:[:el| |
|
608 |
col add:nil. |
|
609 |
]. |
|
610 |
sortBlock := [:entry1 :entry2 | |
|
611 |
((entry1 isNil) or:[entry2 isNil]) ifTrue:[ |
|
612 |
true |
|
613 |
] ifFalse:[ |
|
614 |
false |
|
615 |
] |
|
616 |
]. |
|
617 |
self shouldnt:[col sort:sortBlock] raise:RecursionInterruptSignal. |
|
618 |
||
619 |
" |
|
620 |
self new testOrderedCollection02_SortBigCollection |
|
621 |
" |
|
622 |
! |
|
623 |
||
624 |
testOrderedCollection03_SortBigCollection2 |
|
625 |
| size col| |
|
626 |
||
627 |
size := 12500. |
|
628 |
col := OrderedCollection new. |
|
629 |
1 to:size do:[:el| |
|
630 |
col add:'abc'. |
|
631 |
]. |
|
632 |
self shouldnt:[col sort] raise:RecursionInterruptSignal. |
|
633 |
||
634 |
" |
|
635 |
self new testOrderedCollection03_SortBigCollection2 |
|
636 |
" |
|
637 |
! |
|
638 |
||
639 |
testOrderedCollection04_SortNilsInCollection |
|
640 |
| size col sortBlock| |
|
641 |
||
642 |
size := 125. |
|
643 |
col := OrderedCollection new. |
|
644 |
1 to:size do:[:el| |
|
645 |
col add:nil. |
|
646 |
]. |
|
647 |
sortBlock := [:entry1 :entry2 | |
|
648 |
((entry1 isNil) or:[entry2 isNil]) ifTrue:[ |
|
649 |
true |
|
650 |
] ifFalse:[ |
|
651 |
false |
|
652 |
] |
|
653 |
]. |
|
654 |
"/ col sort:sortBlock. |
|
655 |
self shouldnt:[col sort:sortBlock] raise:RecursionInterruptSignal. |
|
656 |
||
657 |
" |
|
658 |
self new testOrderedCollection04_SortNilsInCollection |
|
659 |
" |
|
655 | 660 |
! |
661 |
||
662 |
testOrderedCollection05_SortRandomCollection |
|
663 |
|data sorted rg coData checkBlock| |
|
664 |
||
665 |
checkBlock := [:a :b| a <= b]. |
|
666 |
rg := Random new. |
|
667 |
||
668 |
#(1 4 11 2000 20011 200000) do:[:eachSize| |
|
669 |
data := Array new:eachSize. |
|
670 |
1 to:data size do:[:i | |
|
671 |
data at:i put:(rg nextIntegerBetween:1 and:100). |
|
672 |
]. |
|
673 |
sorted := data copy sort. |
|
674 |
self checkSorted:sorted with:checkBlock against:data. |
|
675 |
sorted := sorted sort. |
|
676 |
self checkSorted:sorted with:checkBlock against:data. |
|
677 |
sorted := sorted reverse sort. |
|
678 |
self checkSorted:sorted with:checkBlock against:data. |
|
679 |
||
680 |
coData := data copy. |
|
681 |
sorted := data copy sortWith:coData. |
|
682 |
self checkSorted:sorted with:checkBlock against:data. |
|
683 |
self checkSorted:coData with:checkBlock against:data. |
|
684 |
||
685 |
sorted := data copy sort:[:policy :a :b| a < b]. |
|
686 |
self checkSorted:sorted with:checkBlock against:data. |
|
687 |
||
688 |
sorted := data copy sort:[:a :b| a < b]. |
|
689 |
self checkSorted:sorted with:checkBlock against:data. |
|
690 |
||
691 |
coData := data copy. |
|
692 |
sorted := data copy sort:[:a :b| a < b] with:coData. |
|
693 |
self checkSorted:sorted with:checkBlock against:data. |
|
694 |
self checkSorted:coData with:checkBlock against:data. |
|
695 |
]. |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
696 |
! |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
697 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
698 |
testOrderedCollection06_MergeSortRandomCollection |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
699 |
|data sorted rg checkBlock| |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
700 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
701 |
checkBlock := [:a :b| a <= b]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
702 |
rg := Random new. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
703 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
704 |
#(1 4 11 2000 20011 200000) do:[:eachSize| |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
705 |
data := Array new:eachSize. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
706 |
1 to:data size do:[:i | |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
707 |
data at:i put:(rg nextIntegerBetween:1 and:100). |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
708 |
]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
709 |
sorted := data copy mergeSort. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
710 |
self checkSorted:sorted with:checkBlock against:data. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
711 |
sorted := sorted mergeSort. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
712 |
self checkSorted:sorted with:checkBlock against:data. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
713 |
sorted := sorted reverse mergeSort. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
714 |
self checkSorted:sorted with:checkBlock against:data. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
715 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
716 |
sorted := data copy mergeSort:[:a :b| a < b]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
717 |
self checkSorted:sorted with:checkBlock against:data. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
718 |
]. |
657
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
719 |
! |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
720 |
|
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
721 |
testOrderedCollection07_HeapSortRandomCollection |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
722 |
|data sorted rg checkBlock| |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
723 |
|
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
724 |
checkBlock := [:a :b| a <= b]. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
725 |
rg := Random new. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
726 |
|
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
727 |
#(1 4 11 2000 20011 200000) do:[:eachSize| |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
728 |
data := Array new:eachSize. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
729 |
1 to:data size do:[:i | |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
730 |
data at:i put:(rg nextIntegerBetween:1 and:100). |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
731 |
]. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
732 |
sorted := data copy heapSort. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
733 |
self checkSorted:sorted with:checkBlock against:data. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
734 |
sorted := sorted heapSort. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
735 |
self checkSorted:sorted with:checkBlock against:data. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
736 |
sorted := sorted reverse heapSort. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
737 |
self checkSorted:sorted with:checkBlock against:data. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
738 |
|
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
739 |
sorted := data copy heapSort:[:a :b| a < b]. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
740 |
self checkSorted:sorted with:checkBlock against:data. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
741 |
]. |
301 | 742 |
! ! |
743 |
||
744 |
!CollectionTests methodsFor:'tests-orderedDictionary'! |
|
745 |
||
746 |
testOrderedDictionary01 |
|
747 |
|d ret| |
|
748 |
||
749 |
d := OrderedDictionary new. |
|
750 |
||
751 |
self assert: ( d size == 0 ). |
|
752 |
self assert: ( d isEmpty ). |
|
753 |
self assert: ( d notEmpty not ). |
|
754 |
||
755 |
d at:'one' put:1. |
|
756 |
d at:'two' put:2. |
|
757 |
d at:'three' put:3. |
|
758 |
||
759 |
self assert: ( d size == 3 ). |
|
760 |
self assert: ( d isEmpty not). |
|
761 |
self assert: ( d notEmpty ). |
|
762 |
||
585 | 763 |
self assert:((ret := self collectedDoArgsOf:d) sameContentsAs: #(1 2 3)). |
301 | 764 |
|
765 |
self assert: ( (d atIndex:1) == 1 ). |
|
766 |
self assert: ( (d atIndex:2) == 2 ). |
|
767 |
self assert: ( (d atIndex:3) == 3 ). |
|
768 |
||
769 |
self assert: ( (d first) = ('one'->1) ). |
|
770 |
self assert: ( (d last) = ('three'->3) ). |
|
771 |
||
585 | 772 |
self assert:((ret := d collect:[:each | each]) sameContentsAs: #(1 2 3)). |
773 |
self assert:((ret := d select:[:each | true]) sameContentsAs: (OrderedDictionary withAssociations:(Array with:('one'->1) with:('two'->2) with:('three'->3)))). |
|
301 | 774 |
|
775 |
self assert: ( d includes:1 ). |
|
776 |
self assert: ( d includes:2 ). |
|
777 |
self assert: ( d includes:3 ). |
|
778 |
||
779 |
self assert: ( d includesKey:'one' ). |
|
780 |
self assert: ( d includesKey:'two' ). |
|
781 |
self assert: ( d includesKey:'three' ). |
|
782 |
||
783 |
self assert: ((ret := d removeFirst) = 1). |
|
784 |
self assert: ( d size == 2 ). |
|
785 |
self assert: ((ret := d removeLast) = 3). |
|
786 |
self assert: ( d size == 1 ). |
|
787 |
self assert: ((ret := d removeLast) = 2). |
|
788 |
self assert: ( d size == 0 ). |
|
789 |
self assert: ( d isEmpty ). |
|
790 |
self assert: ( d notEmpty not ). |
|
791 |
||
792 |
" |
|
793 |
self basicNew testOrderedDictionary01 |
|
794 |
" |
|
585 | 795 |
|
796 |
"Modified: / 04-07-2011 / 19:32:34 / cg" |
|
301 | 797 |
! ! |
798 |
||
799 |
!CollectionTests methodsFor:'tests-orderedSet'! |
|
162 | 800 |
|
156 | 801 |
testOrderedSet01 |
802 |
|s v1 v2 v3| |
|
803 |
||
804 |
s := OrderedSet new. |
|
805 |
s add:(v1 := 'one'). |
|
806 |
s add:(v2 := 'two'). |
|
807 |
s add:(v3 := 'three'). |
|
808 |
||
809 |
self assert: ( s size == 3 ). |
|
810 |
self assert: ( (s at:1) == v1 ). |
|
811 |
self assert: ( (s at:2) == v2 ). |
|
812 |
self assert: ( (s at:3) == v3 ). |
|
813 |
||
814 |
self assert: ( s includes:v1 ). |
|
815 |
self assert: ( s includes:v2 ). |
|
816 |
self assert: ( s includes:v3 ). |
|
817 |
||
818 |
self assert: ( s includes:v1 copy). |
|
819 |
self assert: ( s includes:v2 copy). |
|
820 |
self assert: ( s includes:v3 copy). |
|
821 |
||
822 |
"already in - adding again should not change things" |
|
823 |
s add:v1. |
|
824 |
self assert: ( s size == 3 ). |
|
825 |
||
826 |
self assert: ( (s at:1) == v1 ). |
|
827 |
self assert: ( (s at:2) == v2 ). |
|
828 |
self assert: ( (s at:3) == v3 ). |
|
829 |
||
830 |
"set i.e. not identitySet - adding copy should not change things" |
|
831 |
s add:v1 copy. |
|
832 |
self assert: ( s size == 3 ). |
|
833 |
||
834 |
self assert: ( (s at:1) == v1 ). |
|
835 |
self assert: ( (s at:2) == v2 ). |
|
836 |
self assert: ( (s at:3) == v3 ). |
|
837 |
||
838 |
s remove:v1. |
|
839 |
||
840 |
self assert: ( s size == 2 ). |
|
841 |
self assert: ( (s at:1) == v2 ). |
|
842 |
self assert: ( (s at:2) == v3 ). |
|
843 |
||
844 |
self assert: ( s includes:v1 ) not. |
|
845 |
self assert: ( s includes:v2 ). |
|
846 |
self assert: ( s includes:v3 ). |
|
847 |
||
848 |
self assert: ( s includes:v1 copy) not. |
|
849 |
self assert: ( s includes:v2 copy). |
|
850 |
self assert: ( s includes:v3 copy). |
|
851 |
||
852 |
s add:v1. |
|
853 |
||
854 |
self assert: ( s size == 3 ). |
|
855 |
self assert: ( (s at:1) == v2 ). |
|
856 |
self assert: ( (s at:2) == v3 ). |
|
857 |
self assert: ( (s at:3) == v1 ). |
|
858 |
||
859 |
self assert: ( s includes:v1 ). |
|
860 |
self assert: ( s includes:v2 ). |
|
861 |
self assert: ( s includes:v3 ). |
|
862 |
||
863 |
self assert: ( s includes:v1 copy). |
|
864 |
self assert: ( s includes:v2 copy). |
|
865 |
self assert: ( s includes:v3 copy). |
|
866 |
||
867 |
s removeLast. |
|
868 |
||
869 |
self assert: ( s size == 2 ). |
|
870 |
self assert: ( (s at:1) == v2 ). |
|
871 |
self assert: ( (s at:2) == v3 ). |
|
872 |
||
873 |
self assert: ( s includes:v1 ) not. |
|
874 |
self assert: ( s includes:v2 ). |
|
875 |
self assert: ( s includes:v3 ). |
|
876 |
||
877 |
self assert: ( s includes:v1 copy) not. |
|
878 |
self assert: ( s includes:v2 copy). |
|
879 |
self assert: ( s includes:v3 copy). |
|
880 |
||
881 |
" |
|
882 |
self basicNew testOrderedSet01 |
|
883 |
" |
|
301 | 884 |
! |
885 |
||
886 |
testOrderedSet02 |
|
887 |
|col| |
|
888 |
||
889 |
col := OrderedSet new. |
|
890 |
||
891 |
col add:'a'. |
|
892 |
col add:'b'. |
|
893 |
col add:'c'. |
|
894 |
self assert:( col size == 3 ). |
|
895 |
self assert:( Array streamContents:[:s | |
|
896 |
col do:[:each | s nextPut:each] |
|
897 |
] |
|
898 |
) = #('a' 'b' 'c' ). |
|
899 |
||
900 |
" |
|
901 |
self new testOrderedSet02 |
|
902 |
" |
|
903 |
! |
|
904 |
||
905 |
testOrderedSet03 |
|
906 |
|col| |
|
907 |
||
908 |
col := OrderedSet new. |
|
909 |
||
910 |
col add:'a'. |
|
911 |
col add:'b'. |
|
912 |
col add:'c'. |
|
913 |
col add:'a'. |
|
914 |
col add:'b'. |
|
915 |
self assert:( col size == 3 ). |
|
916 |
self assert:( Array streamContents:[:s | |
|
917 |
col do:[:each | s nextPut:each] |
|
918 |
] |
|
919 |
) = #('a' 'b' 'c' ). |
|
920 |
||
921 |
" |
|
922 |
self new testOrderedSet03 |
|
923 |
" |
|
924 |
! |
|
925 |
||
926 |
testOrderedSet04 |
|
927 |
|col| |
|
928 |
||
929 |
col := OrderedSet new. |
|
930 |
||
931 |
col add:'a'. |
|
932 |
col addFirst:'b'. |
|
933 |
col addFirst:'c'. |
|
934 |
self assert:( col size == 3 ). |
|
935 |
self assert:( Array streamContents:[:s | |
|
936 |
col do:[:each | s nextPut:each] |
|
937 |
] |
|
938 |
) = #('c' 'b' 'a' ). |
|
939 |
||
940 |
" |
|
941 |
self new testOrderedSet04 |
|
942 |
" |
|
943 |
! |
|
944 |
||
945 |
testOrderedSet05 |
|
946 |
|col| |
|
947 |
||
948 |
col := OrderedSet new. |
|
949 |
||
950 |
col add:'a'. |
|
951 |
col addFirst:'b'. |
|
952 |
col addFirst:'c'. |
|
953 |
col add:'a'. |
|
954 |
col add:'b'. |
|
955 |
col add:'c'. |
|
956 |
self assert:( col size == 3 ). |
|
957 |
self assert:( Array streamContents:[:s | |
|
958 |
col do:[:each | s nextPut:each] |
|
959 |
] |
|
960 |
) = #('c' 'b' 'a' ). |
|
961 |
||
962 |
" |
|
963 |
self new testOrderedSet05 |
|
964 |
" |
|
264 | 965 |
! ! |
966 |
||
297 | 967 |
!CollectionTests methodsFor:'tests-replace'! |
968 |
||
969 |
testEmptyReplace |
|
970 |
| array1 array2 | |
|
971 |
||
972 |
array1 := Array with: 1 with: 2 with: 3 with: 4. |
|
973 |
array2 := Array with: 5 with: 6 with: 7. |
|
974 |
||
975 |
array1 replaceFrom:1 to:0 with:array2 startingAt:1. |
|
976 |
||
977 |
self should: [ array1 = #(1 2 3 4) ]. |
|
978 |
||
979 |
" |
|
980 |
self new testEmptyReplace |
|
981 |
" |
|
538 | 982 |
! |
983 |
||
984 |
testTransliterating |
|
985 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'b-g' to:'B-G' ) = 'aBCDEFGhijkl1234567890'. |
|
986 |
self assert:( 'abcdefghij-kl1234567890' copyTransliterating:'b\-g' to:'B+G' ) = 'aBcdefGhij+kl1234567890'. |
|
987 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'69' to:'96' ) = 'abcdefghijkl1234597860' . |
|
988 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'a' to:'b' ) = 'bbcdefghijkl1234567890' . |
|
989 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'aeiou' to:'AEIOU' ) = 'AbcdEfghIjkl1234567890'. |
|
990 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'QERTYUIOPX' ) = 'abcdefghijklERTYUIOPXQ' . |
|
991 |
||
992 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'A' complement:false squashDuplicates:false ) |
|
993 |
= 'abcdefghijklAAAAAAAAAA'. |
|
994 |
||
995 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'A' complement:false squashDuplicates:true ) |
|
996 |
= 'abcdefghijklA'. |
|
997 |
||
998 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'*' complement:false squashDuplicates:false ) |
|
999 |
= 'abcdefghijkl**********'. |
|
1000 |
||
1001 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'*' complement:true squashDuplicates:false ) |
|
1002 |
= '************1234567890'. |
|
1003 |
||
1004 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'a-zA-Z' to:' ' complement:true squashDuplicates:false ) |
|
1005 |
= 'abcdefghijkl '. |
|
1006 |
||
1007 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'a-zA-Z' to:' ' complement:false squashDuplicates:false ) |
|
1008 |
= ' 1234567890'. |
|
1009 |
||
1010 |
self assert:( 'abcdefghijkl1234567890abcdefghijkl' copyTransliterating:'a-zA-Z' to:'' complement:false squashDuplicates:false ) |
|
1011 |
= '1234567890'. |
|
1012 |
||
1013 |
self assert:( 'abcdefghijkl1234567890abcdefghijkl' copyTransliterating:'a-zA-Z' to:'' complement:true squashDuplicates:false ) |
|
1014 |
= 'abcdefghijklabcdefghijkl'. |
|
297 | 1015 |
! ! |
1016 |
||
639 | 1017 |
!CollectionTests methodsFor:'tests-searching'! |
1018 |
||
1019 |
test_min_max |
|
1020 |
|a| |
|
1021 |
||
1022 |
#( |
|
1023 |
asArray |
|
1024 |
asFloatArray |
|
1025 |
asDoubleArray |
|
1026 |
asSignedIntegerArray |
|
1027 |
) do:[:converter | |
|
640 | 1028 |
|empty| |
1029 |
||
1030 |
empty := #() perform:converter. |
|
1031 |
self should:[ empty min ] raise:Error. |
|
1032 |
self should:[ empty max ] raise:Error. |
|
1033 |
self should:[ empty minMax ] raise:Error. |
|
1034 |
||
639 | 1035 |
#( |
640 | 1036 |
(0 0) |
1037 |
(1 1) |
|
1038 |
(-1 -1) |
|
1039 |
(0 1) |
|
1040 |
(1 2) |
|
1041 |
(-1 -0) |
|
1042 |
(-1 1) |
|
639 | 1043 |
(1 10000) |
1044 |
(1 10001) |
|
1045 |
(2 10000) |
|
1046 |
(2 10001) |
|
1047 |
(-1000 1000) |
|
1048 |
(-1000 999) |
|
1049 |
) pairsDo:[:min :max | |
|
1050 |
a := (min to:max) perform:converter. |
|
1051 |
self assert:(a min) = min. |
|
1052 |
self assert:(a max) = max. |
|
1053 |
self assert:(a minMax) = { min. max }. |
|
1054 |
||
1055 |
a := a reverse. |
|
1056 |
self assert:(a min) = min. |
|
1057 |
self assert:(a max) = max. |
|
1058 |
self assert:(a minMax) = { min. max }. |
|
1059 |
||
1060 |
a := a randomShuffle. |
|
1061 |
self assert:(a min) = min. |
|
1062 |
self assert:(a max) = max. |
|
1063 |
self assert:(a minMax) = { min. max }. |
|
1064 |
]. |
|
1065 |
]. |
|
1066 |
||
1067 |
"Created: / 07-10-2011 / 13:11:36 / cg" |
|
1068 |
! ! |
|
1069 |
||
264 | 1070 |
!CollectionTests methodsFor:'tests-sorting'! |
212 | 1071 |
|
1072 |
testSort01 |
|
1073 |
| col errs last | |
|
1074 |
||
1075 |
col := SortedCollection new addAll: (100 to: 1 by: -1); yourself. |
|
1076 |
last := nil. |
|
1077 |
errs := col inject: 0 into: |
|
1078 |
[ :totIn :n | |totOut| |
|
1079 |
||
1080 |
totOut := totIn. |
|
1081 |
last notNil ifTrue: [ last > n ifTrue: [ totOut := totOut + 1 ] ]. |
|
1082 |
last := n. |
|
1083 |
totOut ]. |
|
1084 |
self should: [ errs = 0 ] |
|
1085 |
||
1086 |
" |
|
1087 |
self basicNew testSort01 |
|
1088 |
" |
|
1089 |
! |
|
1090 |
||
1091 |
testSortStability01 |
|
1092 |
"Verify that the sort is stable" |
|
1093 |
||
1094 |
| testData col lastTestData errs | |
|
1095 |
||
1096 |
testData := OrderedCollection new. |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1097 |
testData addAll: ((111 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]). |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1098 |
testData addAll: ((111 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]). |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1099 |
testData addAll: ((111 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]). |
212 | 1100 |
1 to: testData size do: [ :i | (testData at: i) order: i ]. |
1101 |
||
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1102 |
col := SortedCollection new sortBlock:[ :v1 :v2 | v1 value < v2 value ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1103 |
col addAll: testData. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1104 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1105 |
self checkSorted:col with:[:v1 :v2 | v1 value <= v2 value ] against:testData. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1106 |
|
212 | 1107 |
lastTestData := nil. |
1108 |
||
1109 |
errs := col inject: 0 into: |
|
1110 |
[ :totIn :aSortTestData | |totOut| |
|
1111 |
totOut := totIn. |
|
1112 |
lastTestData notNil ifTrue: |
|
1113 |
[ lastTestData value = aSortTestData value ifTrue: |
|
1114 |
[ lastTestData order > aSortTestData order ifTrue: [ totOut := totOut + 1 ] ] ]. |
|
1115 |
lastTestData := aSortTestData. |
|
1116 |
totOut ]. |
|
1117 |
self should: [ errs = 0 ] |
|
1118 |
||
1119 |
" |
|
1120 |
self basicNew testSortStability01 |
|
1121 |
" |
|
1122 |
! |
|
1123 |
||
1124 |
testSortStability02 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1125 |
"Verify that the sort is stable" |
212 | 1126 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1127 |
| testData col lastTestData errs | |
212 | 1128 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1129 |
testData := OrderedCollection new. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1130 |
(25 to: 1 by: -1) do: [ :i | 1 to: 100 do: [ :j | testData add: (SortTestData new value: i ) ] ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1131 |
1 to: testData size do: [ :i | (testData at: i) order: i ]. |
212 | 1132 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1133 |
col := SortedCollection new sortBlock: [ :v1 :v2 | v1 value < v2 value ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1134 |
col addAll: testData. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1135 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1136 |
self checkSorted:col with:[:v1 :v2 | v1 value <= v2 value ] against:testData. |
212 | 1137 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1138 |
lastTestData := nil. |
212 | 1139 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1140 |
errs := col inject: 0 into: |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1141 |
[ :totIn :aSortTestData | |totOut| |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1142 |
totOut := totIn. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1143 |
lastTestData notNil ifTrue: |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1144 |
[ lastTestData value = aSortTestData value ifTrue: |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1145 |
[ lastTestData order > aSortTestData order ifTrue: [ totOut := totOut + 1 ] ] ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1146 |
lastTestData := aSortTestData. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1147 |
totOut ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1148 |
self should: [ errs = 0 ] |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1149 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1150 |
" |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1151 |
self basicNew testSortStability02 |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1152 |
" |
212 | 1153 |
! ! |
1154 |
||
293 | 1155 |
!CollectionTests methodsFor:'tests-squeak'! |
1156 |
||
1157 |
testIfEmptyifNotEmpty |
|
1158 |
self assert: (empty ifEmpty: [true] ifNotEmpty: [false]). |
|
1159 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [true]). |
|
1160 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [:s | s first = #x]) |
|
1161 |
! |
|
1162 |
||
1163 |
testIfEmptyifNotEmptyDo |
|
1164 |
self assert: (empty ifEmpty: [true] ifNotEmptyDo: [:s | false]). |
|
1165 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmptyDo: [:s | s first = #x]) |
|
1166 |
! |
|
1167 |
||
1168 |
testIfNotEmpty |
|
1169 |
empty ifNotEmpty: [self assert: false]. |
|
1170 |
self assert: (nonEmpty ifNotEmpty: [self]) == self. |
|
1171 |
self assert: (nonEmpty ifNotEmpty: [:s | s first]) = #x |
|
1172 |
! |
|
1173 |
||
1174 |
testIfNotEmptyDo |
|
1175 |
empty ifNotEmptyDo: [:s | self assert: false]. |
|
1176 |
self assert: (nonEmpty ifNotEmptyDo: [:s | s first]) = #x |
|
1177 |
! |
|
1178 |
||
1179 |
testIfNotEmptyDoifNotEmpty |
|
1180 |
self assert: (empty ifNotEmptyDo: [:s | false] ifEmpty: [true]). |
|
1181 |
self assert: (nonEmpty ifNotEmptyDo: [:s | s first = #x] ifEmpty: [false]) |
|
1182 |
! |
|
1183 |
||
1184 |
testIfNotEmptyifEmpty |
|
1185 |
self assert: (empty ifEmpty: [true] ifNotEmpty: [false]). |
|
1186 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [true]). |
|
1187 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [:s | s first = #x]) |
|
1188 |
! ! |
|
1189 |
||
212 | 1190 |
!CollectionTests::SortTestData methodsFor:'accessing'! |
1191 |
||
1192 |
value |
|
1193 |
"Answer the value of the receiver's ''value'' instance variable." |
|
1194 |
||
1195 |
^value |
|
1196 |
! |
|
1197 |
||
1198 |
value: anObject |
|
1199 |
"Set the value of the receiver's ''value'' instance variable to the argument, anObject." |
|
1200 |
||
1201 |
value := anObject |
|
1202 |
! ! |
|
1203 |
||
1204 |
!CollectionTests::SortTestData methodsFor:'order'! |
|
1205 |
||
1206 |
order |
|
1207 |
"Answer the value of the receiver's ''order'' instance variable." |
|
1208 |
||
1209 |
^order |
|
1210 |
! |
|
1211 |
||
1212 |
order: anObject |
|
1213 |
"Set the value of the receiver's ''order'' instance variable to the argument, anObject." |
|
1214 |
||
1215 |
order := anObject |
|
1216 |
! ! |
|
1217 |
||
1218 |
!CollectionTests::SortTestData methodsFor:'printing & storing'! |
|
1219 |
||
1220 |
printOn: aStream |
|
1221 |
super printOn: aStream. |
|
1222 |
aStream |
|
1223 |
nextPutAll: '(value: '; |
|
1224 |
nextPutAll: value printString; |
|
1225 |
nextPutAll: ' order: '; |
|
1226 |
nextPutAll: order printString; |
|
1227 |
nextPut: $) |
|
115 | 1228 |
! ! |
1229 |
||
1230 |
!CollectionTests class methodsFor:'documentation'! |
|
1231 |
||
1232 |
version |
|
1233 |
^ '$Header$' |
|
640 | 1234 |
! |
1235 |
||
1236 |
version_CVS |
|
1237 |
^ '$Header$' |
|
115 | 1238 |
! ! |
757
2d776bef407b
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
677
diff
changeset
|
1239 |