author | Claus Gittinger <cg@exept.de> |
Thu, 14 Apr 2016 19:08:20 +0200 | |
changeset 1393 | 50384f233a0f |
parent 1300 | 3dc512cbf863 |
child 1395 | 7fb21e6bc3ab |
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:'' |
|
1054 | 9 |
category:'tests-Regression-Collections' |
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. |
1043
b95983db1639
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
250 |
self assert: (coll1 size == coll2 size). |
b95983db1639
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
251 |
1 to:coll1 size do:[:i | |
b95983db1639
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
252 |
"/ coll1 at:10 |
b95983db1639
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
253 |
"/ coll2 at:10 |
b95983db1639
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
254 |
self assert:(coll1 at:i) = (coll2 at:i). |
b95983db1639
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
255 |
]. |
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
256 |
self assert: ( coll2 = coll1 ). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
257 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
258 |
coll2 replaceFrom:1 to:coll2 size with:coll1 startingAt:1. |
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 |
"overlapping copy" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
262 |
coll2 replaceFrom:2 to:coll2 size with:coll2 startingAt:1. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
263 |
coll2 replaceFrom:1 to:coll2 size-1 with:coll2 startingAt:2. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
264 |
coll2 at:(coll2 size) put:(coll1 at:coll1 size). |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
265 |
self assert: ( coll2 = coll1 ). |
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 |
self basicNew testSequentialCollectionOperations |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
269 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
270 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
271 |
"Created: / 08-05-2012 / 10:50:08 / cg" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
272 |
! |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
273 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
274 |
protoCollectionFor: aClass |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
275 |
aClass == BooleanArray ifTrue: [ |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
276 |
^ 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
|
277 |
]. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
278 |
aClass == BitArray ifTrue: [ |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
279 |
^ 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
|
280 |
]. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
281 |
aClass == ByteArray ifTrue: [ |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
282 |
^ ByteArray withAll:#(1 2 3 4 16rFC 16rFD 16rFE 16rFF) |
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
283 |
]. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
284 |
aClass == String ifTrue: [ |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
285 |
^ 'abcdefghijklmnopqrstuvwxyz' |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
286 |
]. |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
287 |
(aClass includesBehavior:CharacterArray) ifTrue:[ |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
288 |
^ 'abcdefghijklmnopqrstuvwxyz' 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 |
(aClass includesBehavior:AbstractNumberVector) ifTrue:[ |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
291 |
(aClass includesBehavior:UnboxedIntegerArray) ifTrue:[ |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
292 |
^ #(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
|
293 |
]. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
294 |
^ #(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
|
295 |
]. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
296 |
^ #(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
|
297 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
298 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
299 |
self basicNew testSequentialCollectionOperations |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
300 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
301 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
302 |
"Created: / 08-05-2012 / 10:50:50 / cg" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
303 |
! |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
304 |
|
615 | 305 |
testDictionaryLikeAddRemoveOperations |
306 |
|classes| |
|
307 |
||
308 |
classes := OrderedCollection new. |
|
309 |
classes |
|
310 |
add:Dictionary; |
|
311 |
add:IdentityDictionary; |
|
312 |
add:OrderedDictionary; |
|
313 |
add:BTree. |
|
314 |
||
315 |
classes do:[:eachClass | |
|
316 |
self doTestDictionaryLikeAddRemoveOperationsIn:eachClass |
|
317 |
]. |
|
318 |
||
319 |
" |
|
320 |
self basicNew testDictionaryLikeAddRemoveOperations |
|
321 |
" |
|
322 |
||
323 |
"Created: / 08-08-2011 / 15:59:52 / cg" |
|
324 |
! |
|
325 |
||
326 |
testGeneralAddRemoveOperations |
|
327 |
|classes| |
|
328 |
||
329 |
classes := OrderedCollection new. |
|
330 |
classes |
|
331 |
"/ add:RunArray; |
|
332 |
add:Bag; |
|
333 |
add:Set; |
|
334 |
add:IdentitySet; |
|
335 |
"/add:Dictionary; |
|
336 |
"/add:IdentityDictionary; |
|
337 |
add:OrderedCollection; |
|
338 |
add:SortedCollection; |
|
339 |
"/add:Queue; |
|
340 |
"/add:Stack; |
|
341 |
add:SortedCollection; |
|
342 |
"/add:OrderedDictionary; |
|
343 |
add:OrderedSet. |
|
344 |
"/add:BTree. |
|
345 |
||
346 |
classes do:[:eachClass | |
|
347 |
self doTestGeneralAddRemoveOperationsIn:eachClass |
|
348 |
]. |
|
349 |
||
350 |
" |
|
351 |
self basicNew testGeneralAddRemoveOperations |
|
352 |
" |
|
353 |
||
354 |
"Created: / 08-08-2011 / 15:59:02 / cg" |
|
355 |
! |
|
356 |
||
264 | 357 |
testGeneralOperations |
358 |
|classes| |
|
359 |
||
360 |
classes := OrderedCollection new. |
|
361 |
classes |
|
362 |
add:RunArray; |
|
363 |
add:Bag; |
|
364 |
add:Set; |
|
365 |
add:IdentitySet; |
|
366 |
add:Dictionary; |
|
367 |
add:IdentityDictionary; |
|
368 |
add:OrderedCollection; |
|
369 |
add:SortedCollection; |
|
370 |
add:Queue; |
|
371 |
add:Stack; |
|
372 |
add:SortedCollection; |
|
373 |
add:OrderedDictionary; |
|
615 | 374 |
add:OrderedSet; |
375 |
add:BTree. |
|
264 | 376 |
|
377 |
classes do:[:eachClass | |
|
378 |
self doTestGeneralCollectionOperationsIn:eachClass |
|
379 |
]. |
|
380 |
||
381 |
" |
|
382 |
self basicNew testGeneralOperations |
|
383 |
" |
|
615 | 384 |
|
385 |
"Modified: / 08-08-2011 / 15:53:16 / cg" |
|
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
386 |
! |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
387 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
388 |
testSequentialCollectionOperations |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
389 |
|classes| |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
390 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
391 |
classes := OrderedCollection new. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
392 |
classes |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
393 |
add:OrderedCollection; |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
394 |
add:Array; |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
395 |
add:String; |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
396 |
add:ByteArray; |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
397 |
add:WordArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
398 |
add:IntegerArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
399 |
add:LongIntegerArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
400 |
add:SignedWordArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
401 |
add:SignedIntegerArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
402 |
add:SignedLongIntegerArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
403 |
add:FloatArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
404 |
add:DoubleArray; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
405 |
add:HalfFloatArray; |
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
406 |
add:TwoByteString; |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
407 |
add:Unicode16String; |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
408 |
add:Unicode32String; |
677
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
409 |
add:BooleanArray; |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
410 |
add:BitArray. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
411 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
412 |
classes do:[:eachClass | |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
413 |
self doTestSequentialCollectionOperationsIn:eachClass |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
414 |
]. |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
415 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
416 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
417 |
self basicNew testSequentialCollectionOperations |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
418 |
" |
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
419 |
|
0088726f3063
test overlapping replaceFromToWithStartingAt
Claus Gittinger <cg@exept.de>
parents:
666
diff
changeset
|
420 |
"Created: / 08-05-2012 / 10:48:40 / cg" |
1040
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
421 |
! |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
422 |
|
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
423 |
testSpecialArrayClasses |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
424 |
|a| |
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) asWordArray. |
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) asIntegerArray. |
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 |
a := #(1 2 3 4 5) asLongIntegerArray. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
439 |
self assert:(a at:1) == 1. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
440 |
self assert:(a at:a size) == 5. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
441 |
self assert:(a first) == 1. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
442 |
self assert:(a last) == 5. |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
443 |
|
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
444 |
" |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
445 |
self basicNew testSpecialArrayClasses |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
446 |
" |
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
447 |
|
35d20906f91c
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
757
diff
changeset
|
448 |
"Created: / 08-05-2012 / 10:48:40 / cg" |
1041
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
449 |
! |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
450 |
|
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
451 |
testSpecialArrayClasses2 |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
452 |
|a| |
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) asFloatArray. |
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) asDoubleArray. |
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 |
a := #(1 2 3 4 5) asHalfFloatArray. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
467 |
self assert:(a at:1) = 1.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
468 |
self assert:(a at:a size) = 5.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
469 |
self assert:(a first) = 1.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
470 |
self assert:(a last) = 5.0. |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
471 |
|
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
472 |
" |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
473 |
self basicNew testSpecialArrayClasses2 |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
474 |
" |
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
475 |
|
6692cfae6a25
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
476 |
"Created: / 08-05-2012 / 10:48:40 / cg" |
264 | 477 |
! ! |
478 |
||
479 |
!CollectionTests methodsFor:'tests-interval'! |
|
480 |
||
162 | 481 |
testInterval01 |
663
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
482 |
|i1 i2 enumeratedValues| |
162 | 483 |
|
644 | 484 |
i1 := 1 to:10. |
162 | 485 |
|
644 | 486 |
self assert: ( i1 size == 10 ). |
162 | 487 |
|
644 | 488 |
self assert: ( i1 includes:1 ). |
489 |
self assert: ( i1 includes:10 ). |
|
162 | 490 |
|
644 | 491 |
self assert: ( i1 min == 1 ). |
492 |
self assert: ( i1 max == 10 ). |
|
162 | 493 |
|
494 |
"cannot add/remove" |
|
644 | 495 |
self should:[i1 add:99] raise:Error. |
496 |
self should:[i1 remove:10] raise:Error. |
|
497 |
||
498 |
i2 := 2 to:20 by:2. |
|
499 |
self assert: ( i2 size == 10 ). |
|
500 |
||
501 |
self assert: ( i2 includes:0 ) not. |
|
502 |
self assert: ( i2 includes:1 ) not. |
|
503 |
self assert: ( i2 includes:2 ). |
|
504 |
self assert: ( i2 includes:3 ) not. |
|
505 |
self assert: ( i2 includes:10 ). |
|
506 |
self assert: ( i2 includes:19 ) not. |
|
507 |
self assert: ( i2 includes:20 ). |
|
508 |
self assert: ( i2 includes:21 ) not. |
|
509 |
self assert: ( i2 includes:22 ) not. |
|
510 |
||
511 |
self assert: ( i2 min == 2 ). |
|
512 |
self assert: ( i2 max == 20 ). |
|
513 |
||
514 |
self assert: ( i2 keys asArray = (1 to:10) asArray ). |
|
162 | 515 |
|
663
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
516 |
enumeratedValues := OrderedCollection new. |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
517 |
i1 do:[:each | enumeratedValues add:each ]. |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
518 |
self assert:(enumeratedValues size == 10). |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
519 |
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
|
520 |
|
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
521 |
enumeratedValues := OrderedCollection new. |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
522 |
i2 do:[:each | enumeratedValues add:each ]. |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
523 |
self assert:(enumeratedValues size == 10). |
437a6c228d34
added interval enumeration test
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
524 |
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
|
525 |
|
666 | 526 |
self assert: (i1 collect:[:el | el even]) asArray = #(false true false true false true false true false true). |
527 |
self assert: (i2 collect:[:el | el even]) asArray = #(true true true true true true true true true true). |
|
664 | 528 |
|
162 | 529 |
" |
530 |
self basicNew testInterval01 |
|
531 |
" |
|
644 | 532 |
|
664 | 533 |
"Modified: / 03-05-2012 / 18:36:41 / cg" |
264 | 534 |
! ! |
535 |
||
301 | 536 |
!CollectionTests methodsFor:'tests-orderedCollection'! |
537 |
||
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
538 |
testMergeSortStability01 |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
539 |
"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
|
540 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
541 |
| testData lastTestData errs col| |
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 |
testData := OrderedCollection new. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
544 |
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
|
545 |
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
|
546 |
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
|
547 |
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
|
548 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
549 |
col := testData copy. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
550 |
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
|
551 |
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
|
552 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
553 |
lastTestData := nil. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
554 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
555 |
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
|
556 |
[ :totIn :aSortTestData | |totOut| |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
557 |
totOut := totIn. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
558 |
lastTestData notNil ifTrue: |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
559 |
[ 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
|
560 |
[ 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
|
561 |
lastTestData := aSortTestData. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
562 |
totOut ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
563 |
self should: [ errs = 0 ] |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
564 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
565 |
" |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
566 |
self basicNew testMergeSortStability01 |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
567 |
" |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
568 |
! |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
569 |
|
301 | 570 |
testOrderedCollection01_Sort1 |
571 |
|col col2| |
|
572 |
||
573 |
col := #( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ) copy. |
|
574 |
col sort. |
|
585 | 575 |
self assert:( col sameContentsAs: (1 to:20)). |
301 | 576 |
|
577 |
col := #( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ) copy reverse. |
|
578 |
col sort. |
|
585 | 579 |
self assert:( col sameContentsAs: (1 to:20) ). |
301 | 580 |
|
581 |
col := #( 10 2 13 4 15 6 17 8 19 11 1 12 3 14 5 16 7 18 9 20 ) copy. |
|
582 |
col sort. |
|
585 | 583 |
self assert:( col sameContentsAs: (1 to:20) ). |
301 | 584 |
|
585 |
col := ( 1 to: 10000 ) asOrderedCollection. |
|
586 |
col sort. |
|
585 | 587 |
self assert:( col sameContentsAs: (1 to:10000) ). |
301 | 588 |
|
589 |
col := ( 1 to: 10000 ) asOrderedCollection. |
|
590 |
col2 := ( 1 to: 10000 ) 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 |
col := ( 10000 to: 1 by:-1) asOrderedCollection. |
|
596 |
col2 := ( 10000 to: 1 by:-1) asOrderedCollection. |
|
597 |
col sortWith:col2. |
|
585 | 598 |
self assert:( col sameContentsAs: (1 to:10000) ). |
599 |
self assert:( col2 sameContentsAs: (1 to:10000) ). |
|
301 | 600 |
|
601 |
" |
|
602 |
self new testOrderedCollection01_Sort1 |
|
603 |
" |
|
585 | 604 |
|
605 |
"Modified: / 04-07-2011 / 19:29:54 / cg" |
|
301 | 606 |
! |
607 |
||
608 |
testOrderedCollection02_SortBigCollection |
|
609 |
| size col sortBlock| |
|
610 |
||
611 |
size := 12500. |
|
612 |
col := OrderedCollection new. |
|
613 |
1 to:size do:[:el| |
|
614 |
col add:nil. |
|
615 |
]. |
|
616 |
sortBlock := [:entry1 :entry2 | |
|
617 |
((entry1 isNil) or:[entry2 isNil]) ifTrue:[ |
|
618 |
true |
|
619 |
] ifFalse:[ |
|
620 |
false |
|
621 |
] |
|
622 |
]. |
|
623 |
self shouldnt:[col sort:sortBlock] raise:RecursionInterruptSignal. |
|
624 |
||
625 |
" |
|
626 |
self new testOrderedCollection02_SortBigCollection |
|
627 |
" |
|
628 |
! |
|
629 |
||
630 |
testOrderedCollection03_SortBigCollection2 |
|
631 |
| size col| |
|
632 |
||
633 |
size := 12500. |
|
634 |
col := OrderedCollection new. |
|
635 |
1 to:size do:[:el| |
|
636 |
col add:'abc'. |
|
637 |
]. |
|
638 |
self shouldnt:[col sort] raise:RecursionInterruptSignal. |
|
639 |
||
640 |
" |
|
641 |
self new testOrderedCollection03_SortBigCollection2 |
|
642 |
" |
|
643 |
! |
|
644 |
||
645 |
testOrderedCollection04_SortNilsInCollection |
|
646 |
| size col sortBlock| |
|
647 |
||
648 |
size := 125. |
|
649 |
col := OrderedCollection new. |
|
650 |
1 to:size do:[:el| |
|
651 |
col add:nil. |
|
652 |
]. |
|
653 |
sortBlock := [:entry1 :entry2 | |
|
654 |
((entry1 isNil) or:[entry2 isNil]) ifTrue:[ |
|
655 |
true |
|
656 |
] ifFalse:[ |
|
657 |
false |
|
658 |
] |
|
659 |
]. |
|
660 |
"/ col sort:sortBlock. |
|
661 |
self shouldnt:[col sort:sortBlock] raise:RecursionInterruptSignal. |
|
662 |
||
663 |
" |
|
664 |
self new testOrderedCollection04_SortNilsInCollection |
|
665 |
" |
|
655 | 666 |
! |
667 |
||
668 |
testOrderedCollection05_SortRandomCollection |
|
669 |
|data sorted rg coData checkBlock| |
|
670 |
||
671 |
checkBlock := [:a :b| a <= b]. |
|
672 |
rg := Random new. |
|
673 |
||
674 |
#(1 4 11 2000 20011 200000) do:[:eachSize| |
|
675 |
data := Array new:eachSize. |
|
676 |
1 to:data size do:[:i | |
|
677 |
data at:i put:(rg nextIntegerBetween:1 and:100). |
|
678 |
]. |
|
679 |
sorted := data copy sort. |
|
680 |
self checkSorted:sorted with:checkBlock against:data. |
|
681 |
sorted := sorted sort. |
|
682 |
self checkSorted:sorted with:checkBlock against:data. |
|
683 |
sorted := sorted reverse sort. |
|
684 |
self checkSorted:sorted with:checkBlock against:data. |
|
685 |
||
686 |
coData := data copy. |
|
687 |
sorted := data copy sortWith:coData. |
|
688 |
self checkSorted:sorted with:checkBlock against:data. |
|
689 |
self checkSorted:coData with:checkBlock against:data. |
|
690 |
||
1280
977c1f04083e
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1054
diff
changeset
|
691 |
"/ Policy is not yet supported (without libcompat) |
977c1f04083e
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1054
diff
changeset
|
692 |
"/ sorted := data copy sort:[:policy :a :b| a < b]. |
977c1f04083e
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1054
diff
changeset
|
693 |
"/ self checkSorted:sorted with:checkBlock against:data. |
655 | 694 |
|
695 |
sorted := data copy sort:[:a :b| a < b]. |
|
696 |
self checkSorted:sorted with:checkBlock against:data. |
|
697 |
||
698 |
coData := data copy. |
|
699 |
sorted := data copy sort:[:a :b| a < b] with:coData. |
|
700 |
self checkSorted:sorted with:checkBlock against:data. |
|
701 |
self checkSorted:coData with:checkBlock against:data. |
|
702 |
]. |
|
656
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 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
705 |
testOrderedCollection06_MergeSortRandomCollection |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
706 |
|data sorted rg checkBlock| |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
707 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
708 |
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
|
709 |
rg := Random new. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
710 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
711 |
#(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
|
712 |
data := Array new:eachSize. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
713 |
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
|
714 |
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
|
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. |
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 |
sorted := sorted mergeSort. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
719 |
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
|
720 |
sorted := sorted reverse mergeSort. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
721 |
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
|
722 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
723 |
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
|
724 |
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
|
725 |
]. |
657
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 |
|
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
728 |
testOrderedCollection07_HeapSortRandomCollection |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
729 |
|data sorted rg checkBlock| |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
730 |
|
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
731 |
checkBlock := [:a :b| a <= b]. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
732 |
rg := Random new. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
733 |
|
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
734 |
#(1 4 11 2000 20011 200000) do:[:eachSize| |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
735 |
data := Array new:eachSize. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
736 |
1 to:data size do:[:i | |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
737 |
data at:i put:(rg nextIntegerBetween:1 and:100). |
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. |
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 |
sorted := sorted heapSort. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
742 |
self checkSorted:sorted with:checkBlock against:data. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
743 |
sorted := sorted reverse heapSort. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
744 |
self checkSorted:sorted with:checkBlock against:data. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
745 |
|
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
746 |
sorted := data copy heapSort:[:a :b| a < b]. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
747 |
self checkSorted:sorted with:checkBlock against:data. |
4f04a8bf19c5
added: #testOrderedCollection07_HeapSortRandomCollection
Stefan Vogel <sv@exept.de>
parents:
656
diff
changeset
|
748 |
]. |
301 | 749 |
! ! |
750 |
||
751 |
!CollectionTests methodsFor:'tests-orderedDictionary'! |
|
752 |
||
753 |
testOrderedDictionary01 |
|
754 |
|d ret| |
|
755 |
||
756 |
d := OrderedDictionary new. |
|
757 |
||
758 |
self assert: ( d size == 0 ). |
|
759 |
self assert: ( d isEmpty ). |
|
760 |
self assert: ( d notEmpty not ). |
|
761 |
||
762 |
d at:'one' put:1. |
|
763 |
d at:'two' put:2. |
|
764 |
d at:'three' put:3. |
|
765 |
||
766 |
self assert: ( d size == 3 ). |
|
767 |
self assert: ( d isEmpty not). |
|
768 |
self assert: ( d notEmpty ). |
|
769 |
||
585 | 770 |
self assert:((ret := self collectedDoArgsOf:d) sameContentsAs: #(1 2 3)). |
301 | 771 |
|
772 |
self assert: ( (d atIndex:1) == 1 ). |
|
773 |
self assert: ( (d atIndex:2) == 2 ). |
|
774 |
self assert: ( (d atIndex:3) == 3 ). |
|
775 |
||
776 |
self assert: ( (d first) = ('one'->1) ). |
|
777 |
self assert: ( (d last) = ('three'->3) ). |
|
778 |
||
585 | 779 |
self assert:((ret := d collect:[:each | each]) sameContentsAs: #(1 2 3)). |
780 |
self assert:((ret := d select:[:each | true]) sameContentsAs: (OrderedDictionary withAssociations:(Array with:('one'->1) with:('two'->2) with:('three'->3)))). |
|
301 | 781 |
|
782 |
self assert: ( d includes:1 ). |
|
783 |
self assert: ( d includes:2 ). |
|
784 |
self assert: ( d includes:3 ). |
|
785 |
||
786 |
self assert: ( d includesKey:'one' ). |
|
787 |
self assert: ( d includesKey:'two' ). |
|
788 |
self assert: ( d includesKey:'three' ). |
|
789 |
||
790 |
self assert: ((ret := d removeFirst) = 1). |
|
791 |
self assert: ( d size == 2 ). |
|
792 |
self assert: ((ret := d removeLast) = 3). |
|
793 |
self assert: ( d size == 1 ). |
|
794 |
self assert: ((ret := d removeLast) = 2). |
|
795 |
self assert: ( d size == 0 ). |
|
796 |
self assert: ( d isEmpty ). |
|
797 |
self assert: ( d notEmpty not ). |
|
798 |
||
799 |
" |
|
800 |
self basicNew testOrderedDictionary01 |
|
801 |
" |
|
585 | 802 |
|
803 |
"Modified: / 04-07-2011 / 19:32:34 / cg" |
|
301 | 804 |
! ! |
805 |
||
806 |
!CollectionTests methodsFor:'tests-orderedSet'! |
|
162 | 807 |
|
156 | 808 |
testOrderedSet01 |
809 |
|s v1 v2 v3| |
|
810 |
||
811 |
s := OrderedSet new. |
|
812 |
s add:(v1 := 'one'). |
|
813 |
s add:(v2 := 'two'). |
|
814 |
s add:(v3 := 'three'). |
|
815 |
||
816 |
self assert: ( s size == 3 ). |
|
817 |
self assert: ( (s at:1) == v1 ). |
|
818 |
self assert: ( (s at:2) == v2 ). |
|
819 |
self assert: ( (s at:3) == v3 ). |
|
820 |
||
821 |
self assert: ( s includes:v1 ). |
|
822 |
self assert: ( s includes:v2 ). |
|
823 |
self assert: ( s includes:v3 ). |
|
824 |
||
825 |
self assert: ( s includes:v1 copy). |
|
826 |
self assert: ( s includes:v2 copy). |
|
827 |
self assert: ( s includes:v3 copy). |
|
828 |
||
829 |
"already in - adding again should not change things" |
|
830 |
s add:v1. |
|
831 |
self assert: ( s size == 3 ). |
|
832 |
||
833 |
self assert: ( (s at:1) == v1 ). |
|
834 |
self assert: ( (s at:2) == v2 ). |
|
835 |
self assert: ( (s at:3) == v3 ). |
|
836 |
||
837 |
"set i.e. not identitySet - adding copy should not change things" |
|
838 |
s add:v1 copy. |
|
839 |
self assert: ( s size == 3 ). |
|
840 |
||
841 |
self assert: ( (s at:1) == v1 ). |
|
842 |
self assert: ( (s at:2) == v2 ). |
|
843 |
self assert: ( (s at:3) == v3 ). |
|
844 |
||
845 |
s remove:v1. |
|
846 |
||
847 |
self assert: ( s size == 2 ). |
|
848 |
self assert: ( (s at:1) == v2 ). |
|
849 |
self assert: ( (s at:2) == v3 ). |
|
850 |
||
851 |
self assert: ( s includes:v1 ) not. |
|
852 |
self assert: ( s includes:v2 ). |
|
853 |
self assert: ( s includes:v3 ). |
|
854 |
||
855 |
self assert: ( s includes:v1 copy) not. |
|
856 |
self assert: ( s includes:v2 copy). |
|
857 |
self assert: ( s includes:v3 copy). |
|
858 |
||
859 |
s add:v1. |
|
860 |
||
861 |
self assert: ( s size == 3 ). |
|
862 |
self assert: ( (s at:1) == v2 ). |
|
863 |
self assert: ( (s at:2) == v3 ). |
|
864 |
self assert: ( (s at:3) == v1 ). |
|
865 |
||
866 |
self assert: ( s includes:v1 ). |
|
867 |
self assert: ( s includes:v2 ). |
|
868 |
self assert: ( s includes:v3 ). |
|
869 |
||
870 |
self assert: ( s includes:v1 copy). |
|
871 |
self assert: ( s includes:v2 copy). |
|
872 |
self assert: ( s includes:v3 copy). |
|
873 |
||
874 |
s removeLast. |
|
875 |
||
876 |
self assert: ( s size == 2 ). |
|
877 |
self assert: ( (s at:1) == v2 ). |
|
878 |
self assert: ( (s at:2) == v3 ). |
|
879 |
||
880 |
self assert: ( s includes:v1 ) not. |
|
881 |
self assert: ( s includes:v2 ). |
|
882 |
self assert: ( s includes:v3 ). |
|
883 |
||
884 |
self assert: ( s includes:v1 copy) not. |
|
885 |
self assert: ( s includes:v2 copy). |
|
886 |
self assert: ( s includes:v3 copy). |
|
887 |
||
888 |
" |
|
889 |
self basicNew testOrderedSet01 |
|
890 |
" |
|
301 | 891 |
! |
892 |
||
893 |
testOrderedSet02 |
|
894 |
|col| |
|
895 |
||
896 |
col := OrderedSet new. |
|
897 |
||
898 |
col add:'a'. |
|
899 |
col add:'b'. |
|
900 |
col add:'c'. |
|
901 |
self assert:( col size == 3 ). |
|
902 |
self assert:( Array streamContents:[:s | |
|
903 |
col do:[:each | s nextPut:each] |
|
904 |
] |
|
905 |
) = #('a' 'b' 'c' ). |
|
906 |
||
907 |
" |
|
908 |
self new testOrderedSet02 |
|
909 |
" |
|
910 |
! |
|
911 |
||
912 |
testOrderedSet03 |
|
913 |
|col| |
|
914 |
||
915 |
col := OrderedSet new. |
|
916 |
||
917 |
col add:'a'. |
|
918 |
col add:'b'. |
|
919 |
col add:'c'. |
|
920 |
col add:'a'. |
|
921 |
col add:'b'. |
|
922 |
self assert:( col size == 3 ). |
|
923 |
self assert:( Array streamContents:[:s | |
|
924 |
col do:[:each | s nextPut:each] |
|
925 |
] |
|
926 |
) = #('a' 'b' 'c' ). |
|
927 |
||
928 |
" |
|
929 |
self new testOrderedSet03 |
|
930 |
" |
|
931 |
! |
|
932 |
||
933 |
testOrderedSet04 |
|
934 |
|col| |
|
935 |
||
936 |
col := OrderedSet new. |
|
937 |
||
938 |
col add:'a'. |
|
939 |
col addFirst:'b'. |
|
940 |
col addFirst:'c'. |
|
941 |
self assert:( col size == 3 ). |
|
942 |
self assert:( Array streamContents:[:s | |
|
943 |
col do:[:each | s nextPut:each] |
|
944 |
] |
|
945 |
) = #('c' 'b' 'a' ). |
|
946 |
||
947 |
" |
|
948 |
self new testOrderedSet04 |
|
949 |
" |
|
950 |
! |
|
951 |
||
952 |
testOrderedSet05 |
|
953 |
|col| |
|
954 |
||
955 |
col := OrderedSet new. |
|
956 |
||
957 |
col add:'a'. |
|
958 |
col addFirst:'b'. |
|
959 |
col addFirst:'c'. |
|
960 |
col add:'a'. |
|
961 |
col add:'b'. |
|
962 |
col add:'c'. |
|
963 |
self assert:( col size == 3 ). |
|
964 |
self assert:( Array streamContents:[:s | |
|
965 |
col do:[:each | s nextPut:each] |
|
966 |
] |
|
967 |
) = #('c' 'b' 'a' ). |
|
968 |
||
969 |
" |
|
970 |
self new testOrderedSet05 |
|
971 |
" |
|
264 | 972 |
! ! |
973 |
||
1299 | 974 |
!CollectionTests methodsFor:'tests-reindexedCollection'! |
975 |
||
976 |
testReindexedCollection01 |
|
977 |
|s c c2| |
|
978 |
||
979 |
s := OrderedCollection new. |
|
980 |
s addAll:#('one' 'two' 'three' 'four' 'five'). |
|
981 |
||
982 |
c := s from:2. |
|
983 |
||
984 |
self assert: ( c size == (s size - 1) ). |
|
985 |
1 to:c size do:[:i | |
|
986 |
self assert: ( (c at:i) == (s at:i+1) ). |
|
987 |
]. |
|
988 |
||
989 |
c2 := c collect:[:el |el]. |
|
990 |
self assert:(c2 size == c size). |
|
991 |
self assert:(c2 = c). |
|
992 |
||
993 |
c2 := c select:[:el |true]. |
|
994 |
self assert:(c2 size == c size). |
|
995 |
self assert:(c2 = c). |
|
996 |
||
997 |
c2 := c select:[:el | el startsWith:'t']. |
|
998 |
self assert:(c2 size == (s count:[:el | el startsWith:'t' ])). |
|
999 |
||
1300 | 1000 |
c2 := c reject:[:el | el startsWith:'t']. |
1001 |
self assert:(c2 size == ((s copyFrom:2) count:[:el | el startsWith:'t' ])). |
|
1002 |
||
1003 |
s := #(1 2 3 4 5 6 7 8). |
|
1004 |
c := s from:2. |
|
1005 |
||
1006 |
self assert: ( c size == (s size - 1) ). |
|
1007 |
1 to:c size do:[:i | |
|
1008 |
self assert: ( (c at:i) == (s at:i+1) ). |
|
1009 |
]. |
|
1010 |
||
1011 |
c2 := c collect:[:el |el]. |
|
1012 |
self assert:(c2 size == c size). |
|
1013 |
self assert:(c2 = c). |
|
1014 |
self assert:(c2 sameContentsAs:(s copyFrom:2)). |
|
1015 |
||
1016 |
c2 := c select:[:el |true]. |
|
1017 |
self assert:(c2 size == c size). |
|
1018 |
self assert:(c2 = c). |
|
1019 |
self assert:(c2 sameContentsAs:(s copyFrom:2)). |
|
1020 |
||
1021 |
c2 := c select:[:el |el even]. |
|
1022 |
self assert:(c2 size == ((s copyFrom:2) select:#even) size). |
|
1023 |
self assert:(c2 sameContentsAs:((s copyFrom:2) select:#even)). |
|
1024 |
||
1025 |
c2 := c reject:[:el |el even]. |
|
1026 |
self assert:(c2 size == ((s copyFrom:2) reject:#even) size). |
|
1027 |
self assert:(c2 sameContentsAs:((s copyFrom:2) reject:#even)). |
|
1028 |
||
1299 | 1029 |
" |
1030 |
self basicNew testReindexedCollection01 |
|
1031 |
" |
|
1032 |
! ! |
|
1033 |
||
297 | 1034 |
!CollectionTests methodsFor:'tests-replace'! |
1035 |
||
1036 |
testEmptyReplace |
|
1037 |
| array1 array2 | |
|
1038 |
||
1039 |
array1 := Array with: 1 with: 2 with: 3 with: 4. |
|
1040 |
array2 := Array with: 5 with: 6 with: 7. |
|
1041 |
||
1042 |
array1 replaceFrom:1 to:0 with:array2 startingAt:1. |
|
1043 |
||
1044 |
self should: [ array1 = #(1 2 3 4) ]. |
|
1045 |
||
1046 |
" |
|
1047 |
self new testEmptyReplace |
|
1048 |
" |
|
538 | 1049 |
! |
1050 |
||
1051 |
testTransliterating |
|
1052 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'b-g' to:'B-G' ) = 'aBCDEFGhijkl1234567890'. |
|
1053 |
self assert:( 'abcdefghij-kl1234567890' copyTransliterating:'b\-g' to:'B+G' ) = 'aBcdefGhij+kl1234567890'. |
|
1054 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'69' to:'96' ) = 'abcdefghijkl1234597860' . |
|
1055 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'a' to:'b' ) = 'bbcdefghijkl1234567890' . |
|
1056 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'aeiou' to:'AEIOU' ) = 'AbcdEfghIjkl1234567890'. |
|
1057 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'QERTYUIOPX' ) = 'abcdefghijklERTYUIOPXQ' . |
|
1058 |
||
1059 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'A' complement:false squashDuplicates:false ) |
|
1060 |
= 'abcdefghijklAAAAAAAAAA'. |
|
1061 |
||
1062 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'A' complement:false squashDuplicates:true ) |
|
1063 |
= 'abcdefghijklA'. |
|
1064 |
||
1065 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'*' complement:false squashDuplicates:false ) |
|
1066 |
= 'abcdefghijkl**********'. |
|
1067 |
||
1068 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'0-9' to:'*' complement:true squashDuplicates:false ) |
|
1069 |
= '************1234567890'. |
|
1070 |
||
1071 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'a-zA-Z' to:' ' complement:true squashDuplicates:false ) |
|
1072 |
= 'abcdefghijkl '. |
|
1073 |
||
1074 |
self assert:( 'abcdefghijkl1234567890' copyTransliterating:'a-zA-Z' to:' ' complement:false squashDuplicates:false ) |
|
1075 |
= ' 1234567890'. |
|
1076 |
||
1077 |
self assert:( 'abcdefghijkl1234567890abcdefghijkl' copyTransliterating:'a-zA-Z' to:'' complement:false squashDuplicates:false ) |
|
1078 |
= '1234567890'. |
|
1079 |
||
1080 |
self assert:( 'abcdefghijkl1234567890abcdefghijkl' copyTransliterating:'a-zA-Z' to:'' complement:true squashDuplicates:false ) |
|
1081 |
= 'abcdefghijklabcdefghijkl'. |
|
297 | 1082 |
! ! |
1083 |
||
639 | 1084 |
!CollectionTests methodsFor:'tests-searching'! |
1085 |
||
1086 |
test_min_max |
|
1087 |
|a| |
|
1088 |
||
1089 |
#( |
|
1090 |
asArray |
|
1091 |
asFloatArray |
|
1092 |
asDoubleArray |
|
1044
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1093 |
asHalfFloatArray |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1094 |
asSignedWordArray |
639 | 1095 |
asSignedIntegerArray |
1044
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1096 |
asSignedLongIntegerArray |
639 | 1097 |
) do:[:converter | |
640 | 1098 |
|empty| |
1099 |
||
1100 |
empty := #() perform:converter. |
|
1101 |
self should:[ empty min ] raise:Error. |
|
1102 |
self should:[ empty max ] raise:Error. |
|
1103 |
self should:[ empty minMax ] raise:Error. |
|
1104 |
||
639 | 1105 |
#( |
640 | 1106 |
(0 0) |
1107 |
(1 1) |
|
1108 |
(-1 -1) |
|
1109 |
(0 1) |
|
1110 |
(1 2) |
|
1111 |
(-1 -0) |
|
1112 |
(-1 1) |
|
639 | 1113 |
(1 10000) |
1044
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1114 |
(1 20000) |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1115 |
(2 10000) |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1116 |
(2 20000) |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1117 |
(-1000 1000) |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1118 |
(-1000 999) |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1119 |
) pairsDo:[:min :max | |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1120 |
a := (min to:max) perform:converter. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1121 |
self assert:(a min) = min. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1122 |
self assert:(a max) = max. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1123 |
self assert:(a minMax) = { min. max }. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1124 |
|
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1125 |
a := a reverse. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1126 |
self assert:(a min) = min. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1127 |
self assert:(a max) = max. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1128 |
self assert:(a minMax) = { min. max }. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1129 |
|
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1130 |
a := a randomShuffle. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1131 |
self assert:(a min) = min. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1132 |
self assert:(a max) = max. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1133 |
self assert:(a minMax) = { min. max }. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1134 |
]. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1135 |
]. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1136 |
|
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1137 |
#( |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1138 |
asWordArray |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1139 |
asIntegerArray |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1140 |
asLongIntegerArray |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1141 |
) do:[:converter | |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1142 |
|empty| |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1143 |
|
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1144 |
empty := #() perform:converter. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1145 |
self should:[ empty min ] raise:Error. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1146 |
self should:[ empty max ] raise:Error. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1147 |
self should:[ empty minMax ] raise:Error. |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1148 |
|
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1149 |
#( |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1150 |
(0 0) |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1151 |
(1 1) |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1152 |
(0 1) |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1153 |
(1 2) |
b019cfae53af
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
1154 |
(1 10000) |
639 | 1155 |
(1 10001) |
1156 |
(2 10000) |
|
1157 |
(2 10001) |
|
1158 |
) pairsDo:[:min :max | |
|
1159 |
a := (min to:max) perform:converter. |
|
1160 |
self assert:(a min) = min. |
|
1161 |
self assert:(a max) = max. |
|
1162 |
self assert:(a minMax) = { min. max }. |
|
1163 |
||
1164 |
a := a reverse. |
|
1165 |
self assert:(a min) = min. |
|
1166 |
self assert:(a max) = max. |
|
1167 |
self assert:(a minMax) = { min. max }. |
|
1168 |
||
1169 |
a := a randomShuffle. |
|
1170 |
self assert:(a min) = min. |
|
1171 |
self assert:(a max) = max. |
|
1172 |
self assert:(a minMax) = { min. max }. |
|
1173 |
]. |
|
1174 |
]. |
|
1175 |
||
1176 |
"Created: / 07-10-2011 / 13:11:36 / cg" |
|
1177 |
! ! |
|
1178 |
||
264 | 1179 |
!CollectionTests methodsFor:'tests-sorting'! |
212 | 1180 |
|
1049
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1181 |
testLargest |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1182 |
| col | |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1183 |
|
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1184 |
col := #(5 16 3 18 17 15 2 12 1 8 14 10 7 11 20 4 19 6 13 9). |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1185 |
self assert:(col max == 20). |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1186 |
self assert:(col largest:4) asArray = #(17 18 19 20). |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1187 |
self assert:(col smallest:4) asArray = #(1 2 3 4). |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1188 |
|
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1189 |
self assert:(col keysOfLargest:4) asArray = #(5 4 17 15). |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1190 |
self assert:(col keysOfSmallest:4) asArray = #(9 7 3 16). |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1191 |
|
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1192 |
" |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1193 |
self basicNew testLargest |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1194 |
" |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1195 |
! |
c5c7858fe11e
class: RegressionTests::CollectionTests
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1196 |
|
212 | 1197 |
testSort01 |
1198 |
| col errs last | |
|
1199 |
||
1200 |
col := SortedCollection new addAll: (100 to: 1 by: -1); yourself. |
|
1201 |
last := nil. |
|
1202 |
errs := col inject: 0 into: |
|
1203 |
[ :totIn :n | |totOut| |
|
1204 |
||
1205 |
totOut := totIn. |
|
1206 |
last notNil ifTrue: [ last > n ifTrue: [ totOut := totOut + 1 ] ]. |
|
1207 |
last := n. |
|
1208 |
totOut ]. |
|
1209 |
self should: [ errs = 0 ] |
|
1210 |
||
1211 |
" |
|
1212 |
self basicNew testSort01 |
|
1213 |
" |
|
1214 |
! |
|
1215 |
||
1216 |
testSortStability01 |
|
1217 |
"Verify that the sort is stable" |
|
1218 |
||
1219 |
| testData col lastTestData errs | |
|
1220 |
||
1221 |
testData := OrderedCollection new. |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1222 |
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
|
1223 |
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
|
1224 |
testData addAll: ((111 to: 1 by: -1) collect: [ :n | SortTestData new value: n ]). |
212 | 1225 |
1 to: testData size do: [ :i | (testData at: i) order: i ]. |
1226 |
||
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1227 |
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
|
1228 |
col addAll: testData. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1229 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1230 |
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
|
1231 |
|
212 | 1232 |
lastTestData := nil. |
1233 |
||
1234 |
errs := col inject: 0 into: |
|
1235 |
[ :totIn :aSortTestData | |totOut| |
|
1236 |
totOut := totIn. |
|
1237 |
lastTestData notNil ifTrue: |
|
1238 |
[ lastTestData value = aSortTestData value ifTrue: |
|
1239 |
[ lastTestData order > aSortTestData order ifTrue: [ totOut := totOut + 1 ] ] ]. |
|
1240 |
lastTestData := aSortTestData. |
|
1241 |
totOut ]. |
|
1242 |
self should: [ errs = 0 ] |
|
1243 |
||
1244 |
" |
|
1245 |
self basicNew testSortStability01 |
|
1246 |
" |
|
1247 |
! |
|
1248 |
||
1249 |
testSortStability02 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1250 |
"Verify that the sort is stable" |
212 | 1251 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1252 |
| testData col lastTestData errs | |
212 | 1253 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1254 |
testData := OrderedCollection new. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1255 |
(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
|
1256 |
1 to: testData size do: [ :i | (testData at: i) order: i ]. |
212 | 1257 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1258 |
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
|
1259 |
col addAll: testData. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1260 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1261 |
self checkSorted:col with:[:v1 :v2 | v1 value <= v2 value ] against:testData. |
212 | 1262 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1263 |
lastTestData := nil. |
212 | 1264 |
|
656
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1265 |
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
|
1266 |
[ :totIn :aSortTestData | |totOut| |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1267 |
totOut := totIn. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1268 |
lastTestData notNil ifTrue: |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1269 |
[ 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
|
1270 |
[ 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
|
1271 |
lastTestData := aSortTestData. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1272 |
totOut ]. |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1273 |
self should: [ errs = 0 ] |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1274 |
|
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1275 |
" |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1276 |
self basicNew testSortStability02 |
470e994fc84b
Fix stability tests (they didn't work after being fixed).
Stefan Vogel <sv@exept.de>
parents:
655
diff
changeset
|
1277 |
" |
1282
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1278 |
! |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1279 |
|
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1280 |
testSortedCollectionQueries |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1281 |
"test a SortedCollection, where only a single attribute is used for sorting. |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1282 |
#include: failed before 2015-06-24" |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1283 |
|
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1284 |
|collection| |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1285 |
|
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1286 |
collection := SortedCollection sortBlock:[:a :b | a key < b key ]. |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1287 |
$a to:$z do:[:l | |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1288 |
1 to:100 do:[:i | |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1289 |
collection add:(Association key:l value:i) |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1290 |
]. |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1291 |
]. |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1292 |
|
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1293 |
"/ make startIndex > 1 and endIndex < size |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1294 |
|
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1295 |
collection |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1296 |
removeFirst; |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1297 |
removeLast. |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1298 |
collection |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1299 |
keysAndValuesDo:[:eachIndex :eachElement | |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1300 |
self assert:(collection detect:[:el | el = eachElement ]) notNil. |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1301 |
self assert:(collection includes:eachElement). |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1302 |
self assert:(collection indexOf:eachElement) = eachIndex. |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1303 |
self assert:(collection occurrencesOf:eachElement) = 1. |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1304 |
self |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1305 |
assert:(collection |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1306 |
includes:(eachElement copy value:(eachElement value + 1000))) not. |
e64a9d280572
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
1280
diff
changeset
|
1307 |
]. |
212 | 1308 |
! ! |
1309 |
||
293 | 1310 |
!CollectionTests methodsFor:'tests-squeak'! |
1311 |
||
1312 |
testIfEmptyifNotEmpty |
|
1313 |
self assert: (empty ifEmpty: [true] ifNotEmpty: [false]). |
|
1314 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [true]). |
|
1315 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [:s | s first = #x]) |
|
1316 |
! |
|
1317 |
||
1318 |
testIfEmptyifNotEmptyDo |
|
1319 |
self assert: (empty ifEmpty: [true] ifNotEmptyDo: [:s | false]). |
|
1320 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmptyDo: [:s | s first = #x]) |
|
1321 |
! |
|
1322 |
||
1323 |
testIfNotEmpty |
|
1324 |
empty ifNotEmpty: [self assert: false]. |
|
1325 |
self assert: (nonEmpty ifNotEmpty: [self]) == self. |
|
1326 |
self assert: (nonEmpty ifNotEmpty: [:s | s first]) = #x |
|
1327 |
! |
|
1328 |
||
1329 |
testIfNotEmptyDo |
|
1330 |
empty ifNotEmptyDo: [:s | self assert: false]. |
|
1331 |
self assert: (nonEmpty ifNotEmptyDo: [:s | s first]) = #x |
|
1332 |
! |
|
1333 |
||
1334 |
testIfNotEmptyDoifNotEmpty |
|
1335 |
self assert: (empty ifNotEmptyDo: [:s | false] ifEmpty: [true]). |
|
1336 |
self assert: (nonEmpty ifNotEmptyDo: [:s | s first = #x] ifEmpty: [false]) |
|
1337 |
! |
|
1338 |
||
1339 |
testIfNotEmptyifEmpty |
|
1340 |
self assert: (empty ifEmpty: [true] ifNotEmpty: [false]). |
|
1341 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [true]). |
|
1342 |
self assert: (nonEmpty ifEmpty: [false] ifNotEmpty: [:s | s first = #x]) |
|
1343 |
! ! |
|
1344 |
||
212 | 1345 |
!CollectionTests::SortTestData methodsFor:'accessing'! |
1346 |
||
1347 |
value |
|
1348 |
"Answer the value of the receiver's ''value'' instance variable." |
|
1349 |
||
1350 |
^value |
|
1351 |
! |
|
1352 |
||
1353 |
value: anObject |
|
1354 |
"Set the value of the receiver's ''value'' instance variable to the argument, anObject." |
|
1355 |
||
1356 |
value := anObject |
|
1357 |
! ! |
|
1358 |
||
1359 |
!CollectionTests::SortTestData methodsFor:'order'! |
|
1360 |
||
1361 |
order |
|
1362 |
"Answer the value of the receiver's ''order'' instance variable." |
|
1363 |
||
1364 |
^order |
|
1365 |
! |
|
1366 |
||
1367 |
order: anObject |
|
1368 |
"Set the value of the receiver's ''order'' instance variable to the argument, anObject." |
|
1369 |
||
1370 |
order := anObject |
|
1371 |
! ! |
|
1372 |
||
1373 |
!CollectionTests::SortTestData methodsFor:'printing & storing'! |
|
1374 |
||
1375 |
printOn: aStream |
|
1376 |
super printOn: aStream. |
|
1377 |
aStream |
|
1378 |
nextPutAll: '(value: '; |
|
1379 |
nextPutAll: value printString; |
|
1380 |
nextPutAll: ' order: '; |
|
1381 |
nextPutAll: order printString; |
|
1382 |
nextPut: $) |
|
115 | 1383 |
! ! |
1384 |
||
1385 |
!CollectionTests class methodsFor:'documentation'! |
|
1386 |
||
1387 |
version |
|
1388 |
^ '$Header$' |
|
640 | 1389 |
! |
1390 |
||
1391 |
version_CVS |
|
1392 |
^ '$Header$' |
|
115 | 1393 |
! ! |
757
2d776bef407b
class: RegressionTests::CollectionTests
Stefan Vogel <sv@exept.de>
parents:
677
diff
changeset
|
1394 |