author | convert-repo |
Wed, 04 Jul 2018 03:33:29 +0000 | |
changeset 1985 | 89923f26ec8a |
parent 1882 | b4bb993596b6 |
child 2109 | 851570e26c15 |
permissions | -rw-r--r-- |
1447 | 1 |
"{ Package: 'stx:goodies/regression' }" |
310 | 2 |
|
3 |
"{ NameSpace: RegressionTests }" |
|
4 |
||
5 |
TestCase subclass:#SmallIntegerTest |
|
6 |
instanceVariableNames:'' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
1074 | 9 |
category:'tests-Regression-Numbers' |
310 | 10 |
! |
11 |
||
12 |
||
619
f918fa22ad81
Circumvent compiler error about div by zero
Stefan Vogel <sv@exept.de>
parents:
364
diff
changeset
|
13 |
!SmallIntegerTest class methodsFor:'others'! |
f918fa22ad81
Circumvent compiler error about div by zero
Stefan Vogel <sv@exept.de>
parents:
364
diff
changeset
|
14 |
|
f918fa22ad81
Circumvent compiler error about div by zero
Stefan Vogel <sv@exept.de>
parents:
364
diff
changeset
|
15 |
version_CVS |
f918fa22ad81
Circumvent compiler error about div by zero
Stefan Vogel <sv@exept.de>
parents:
364
diff
changeset
|
16 |
^ '$Header$' |
f918fa22ad81
Circumvent compiler error about div by zero
Stefan Vogel <sv@exept.de>
parents:
364
diff
changeset
|
17 |
! ! |
f918fa22ad81
Circumvent compiler error about div by zero
Stefan Vogel <sv@exept.de>
parents:
364
diff
changeset
|
18 |
|
310 | 19 |
!SmallIntegerTest methodsFor:'tests-arithmetic'! |
20 |
||
1347 | 21 |
testBitShift |
1447 | 22 |
#( |
23 |
(1 1 2) |
|
24 |
(1 2 4) |
|
25 |
(1 3 8) |
|
26 |
(1 7 16r080) |
|
27 |
(1 8 16r100) |
|
28 |
(1 15 16r08000) |
|
29 |
(1 16 16r10000) |
|
30 |
(1 17 16r20000) |
|
31 |
(1 30 16r040000000) |
|
32 |
(1 31 16r080000000) |
|
33 |
(1 32 16r100000000) |
|
34 |
(1 33 16r200000000) |
|
1347 | 35 |
|
1447 | 36 |
(1 62 16r04000000000000000) |
37 |
(1 63 16r08000000000000000) |
|
38 |
(1 64 16r10000000000000000) |
|
39 |
(1 65 16r20000000000000000) |
|
1347 | 40 |
|
1447 | 41 |
(1 126 16r040000000000000000000000000000000) |
42 |
(1 127 16r080000000000000000000000000000000) |
|
43 |
(1 128 16r100000000000000000000000000000000) |
|
44 |
(1 129 16r200000000000000000000000000000000) |
|
1347 | 45 |
|
1447 | 46 |
(16r10 1 16r20) |
47 |
(16r10 2 16r40) |
|
48 |
(16r10 3 16r80) |
|
49 |
(16r10 7 16r0800) |
|
50 |
(16r10 8 16r1000) |
|
51 |
(16r10 15 16r080000) |
|
52 |
(16r10 16 16r100000) |
|
53 |
(16r10 17 16r200000) |
|
54 |
(16r10 30 16r0400000000) |
|
55 |
(16r10 31 16r0800000000) |
|
56 |
(16r10 32 16r1000000000) |
|
57 |
(16r10 33 16r2000000000) |
|
1347 | 58 |
|
1447 | 59 |
(16r10 62 16r040000000000000000) |
60 |
(16r10 63 16r080000000000000000) |
|
61 |
(16r10 64 16r100000000000000000) |
|
62 |
(16r10 65 16r200000000000000000) |
|
1347 | 63 |
|
1447 | 64 |
(16r10 126 16r0400000000000000000000000000000000) |
65 |
(16r10 127 16r0800000000000000000000000000000000) |
|
66 |
(16r10 128 16r1000000000000000000000000000000000) |
|
67 |
(16r10 129 16r2000000000000000000000000000000000) |
|
1347 | 68 |
) triplesDo:[:val :cnt :expected | |
1447 | 69 |
|rslt1 rslt2| |
70 |
||
71 |
rslt1 := val bitShift:cnt. |
|
72 |
self assert:(rslt1 = expected). |
|
73 |
expected class == SmallInteger ifTrue:[ |
|
74 |
self assert:(rslt1 == expected) |
|
75 |
]. |
|
76 |
rslt2 := rslt1 bitShift:cnt negated. |
|
77 |
self assert:(rslt2 = val). |
|
78 |
val class == SmallInteger ifTrue:[ |
|
79 |
self assert:(rslt2 == val) |
|
80 |
]. |
|
1347 | 81 |
]. |
82 |
! |
|
83 |
||
84 |
testBitShiftNegative |
|
1447 | 85 |
#( |
1709 | 86 |
(-1 1 -2) |
87 |
(-1 2 -4) |
|
88 |
(-1 3 -8) |
|
89 |
(-1 7 16r-080) |
|
90 |
(-1 8 16r-100) |
|
91 |
(-1 15 16r-08000) |
|
92 |
(-1 16 16r-10000) |
|
93 |
(-1 17 16r-20000) |
|
94 |
(-1 30 16r-040000000) |
|
95 |
(-1 31 16r-080000000) |
|
96 |
(-1 32 16r-100000000) |
|
97 |
(-1 33 16r-200000000) |
|
1347 | 98 |
|
1709 | 99 |
(-1 62 16r-04000000000000000) |
100 |
(-1 63 16r-08000000000000000) |
|
101 |
(-1 64 16r-10000000000000000) |
|
102 |
(-1 65 16r-20000000000000000) |
|
1347 | 103 |
|
1709 | 104 |
(-1 126 16r-040000000000000000000000000000000) |
105 |
(-1 127 16r-080000000000000000000000000000000) |
|
106 |
(-1 128 16r-100000000000000000000000000000000) |
|
107 |
(-1 129 16r-200000000000000000000000000000000) |
|
1347 | 108 |
|
1709 | 109 |
(16r-10 1 16r-20) |
110 |
(16r-10 2 16r-40) |
|
111 |
(16r-10 3 16r-80) |
|
112 |
(16r-10 7 16r-0800) |
|
113 |
(16r-10 8 16r-1000) |
|
114 |
(16r-10 15 16r-080000) |
|
115 |
(16r-10 16 16r-100000) |
|
116 |
(16r-10 17 16r-200000) |
|
117 |
(16r-10 30 16r-0400000000) |
|
118 |
(16r-10 31 16r-0800000000) |
|
119 |
(16r-10 32 16r-1000000000) |
|
120 |
(16r-10 33 16r-2000000000) |
|
1347 | 121 |
|
1709 | 122 |
(16r-10 62 16r-040000000000000000) |
123 |
(16r-10 63 16r-080000000000000000) |
|
124 |
(16r-10 64 16r-100000000000000000) |
|
125 |
(16r-10 65 16r-200000000000000000) |
|
1347 | 126 |
|
1709 | 127 |
(16r-10 126 16r-0400000000000000000000000000000000) |
128 |
(16r-10 127 16r-0800000000000000000000000000000000) |
|
129 |
(16r-10 128 16r-1000000000000000000000000000000000) |
|
130 |
(16r-10 129 16r-2000000000000000000000000000000000) |
|
1347 | 131 |
) triplesDo:[:val :cnt :expected | |
1709 | 132 |
|rslt1 rslt2| |
1447 | 133 |
|
1709 | 134 |
rslt1 := val bitShift:cnt. |
135 |
self assert:(rslt1 = expected). |
|
136 |
expected class == SmallInteger ifTrue:[ |
|
137 |
self assert:(rslt1 == expected) |
|
138 |
]. |
|
139 |
rslt2 := rslt1 bitShift:cnt negated. |
|
140 |
self assert:(rslt2 = val). |
|
141 |
val class == SmallInteger ifTrue:[ |
|
142 |
self assert:(rslt2 == val) |
|
143 |
]. |
|
1347 | 144 |
]. |
1709 | 145 |
|
146 |
"Modified (format): / 19-09-2017 / 16:29:36 / stefan" |
|
1347 | 147 |
! |
148 |
||
310 | 149 |
testDivide |
1835 | 150 |
|zero us1 us2 us3 us4 usm2 usm4| |
619
f918fa22ad81
Circumvent compiler error about div by zero
Stefan Vogel <sv@exept.de>
parents:
364
diff
changeset
|
151 |
|
1835 | 152 |
"circumvent compiler error about division by zero" |
153 |
zero := 0. |
|
619
f918fa22ad81
Circumvent compiler error about div by zero
Stefan Vogel <sv@exept.de>
parents:
364
diff
changeset
|
154 |
|
1835 | 155 |
self assert: 2 / 1 = 2. |
156 |
self assert: (3 / 2) isFraction. |
|
157 |
self assert: 4 / 2 = 2. |
|
158 |
self assert: 4 / -2 = -2. |
|
159 |
self assert: -4 / 2 = -2. |
|
160 |
self assert: -4 / -2 = 2. |
|
161 |
self should: [ 1 / zero ] raise: ZeroDivide. |
|
1223
708a62eac280
class: RegressionTests::SmallIntegerTest
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
162 |
|
1835 | 163 |
us1 := 1. |
164 |
us2 := 2. |
|
165 |
us3 := 3. |
|
166 |
us4 := 4. |
|
167 |
usm2 := -2. |
|
168 |
usm4 := -4. |
|
1223
708a62eac280
class: RegressionTests::SmallIntegerTest
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
169 |
|
1835 | 170 |
self assert: us2 / us1 = us2. |
171 |
self assert: (us3 / us2) isFraction. |
|
172 |
self assert: us4 / us2 = 2. |
|
173 |
self assert: us4 / usm2 = -2. |
|
174 |
self assert: usm4 / us2 = -2. |
|
175 |
self assert: usm4 / usm2 = 2. |
|
364 | 176 |
! |
177 |
||
178 |
testMultiply |
|
179 |
|i ii| |
|
180 |
||
1447 | 181 |
#( |
182 |
16r3fff |
|
183 |
16r7fff |
|
184 |
16rffff |
|
185 |
16r3fffffff |
|
186 |
16r7fffffff |
|
187 |
16rffffffff |
|
188 |
16r20000000 |
|
189 |
16r40000000 |
|
190 |
16r80000000 |
|
191 |
16r100000000 |
|
192 |
16r20000001 |
|
193 |
16r40000001 |
|
194 |
16r80000001 |
|
195 |
16r100000001 |
|
1223
708a62eac280
class: RegressionTests::SmallIntegerTest
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
196 |
|
1447 | 197 |
"/ for 64 bit machines: |
198 |
16r3fffffffffffffff |
|
199 |
16r7fffffffffffffff |
|
200 |
16rffffffffffffffff |
|
201 |
16r2000000000000000 |
|
202 |
16r4000000000000000 |
|
203 |
16r8000000000000000 |
|
204 |
16r10000000000000000 |
|
205 |
16r2000000000000001 |
|
206 |
16r4000000000000001 |
|
207 |
16r8000000000000001 |
|
208 |
16r10000000000000001 |
|
364 | 209 |
) do:[:x | |
1447 | 210 |
i := x. |
211 |
ii := i * i. |
|
212 |
self assert:((ii / i) = i). |
|
213 |
i class == SmallInteger ifTrue:[ |
|
214 |
self assert:((ii / i) == i). |
|
215 |
]. |
|
364 | 216 |
|
1447 | 217 |
i := x negated. |
218 |
ii := i * i. |
|
219 |
self assert:((ii / i) = i). |
|
220 |
i class == SmallInteger ifTrue:[ |
|
221 |
self assert:((ii / i) == i). |
|
222 |
]. |
|
364 | 223 |
]. |
224 |
! |
|
225 |
||
226 |
testNegation |
|
1596 | 227 |
|i iN iNN iNNN| |
364 | 228 |
|
1447 | 229 |
#( |
1596 | 230 |
16r1fffffff |
231 |
16r3fffffff |
|
232 |
16r7fffffff |
|
233 |
16rffffffff |
|
234 |
16r20000000 |
|
235 |
16r40000000 |
|
236 |
16r80000000 |
|
237 |
16r100000000 |
|
238 |
16r20000001 |
|
239 |
16r40000001 |
|
240 |
16r80000001 |
|
241 |
16r100000001 |
|
1223
708a62eac280
class: RegressionTests::SmallIntegerTest
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
242 |
|
1596 | 243 |
"/ for 64bit machines: |
244 |
16r3fffffffffffffff |
|
245 |
16r7fffffffffffffff |
|
246 |
16rffffffffffffffff |
|
247 |
16r2000000000000000 |
|
248 |
16r4000000000000000 |
|
249 |
16r8000000000000000 |
|
250 |
16r10000000000000000 |
|
251 |
16r2000000000000001 |
|
252 |
16r4000000000000001 |
|
253 |
16r8000000000000001 |
|
254 |
16r10000000000000001 |
|
364 | 255 |
) do:[:x | |
1596 | 256 |
i := x. |
257 |
iN := i negated. |
|
258 |
iNN := iN negated. |
|
259 |
iNNN := iNN negated. |
|
260 |
self assert:(i = iNN). |
|
261 |
i class == SmallInteger ifTrue:[ |
|
262 |
self assert:(i == iNN). |
|
263 |
]. |
|
264 |
self assert:(iN = iNNN). |
|
265 |
iN class == SmallInteger ifTrue:[ |
|
266 |
self assert:(iN == iNNN). |
|
267 |
]. |
|
364 | 268 |
]. |
1306 | 269 |
self assert:(SmallInteger maxVal negated class == SmallInteger). |
270 |
self assert:(SmallInteger maxVal negated negated == SmallInteger maxVal). |
|
1447 | 271 |
|
1306 | 272 |
self assert:(SmallInteger maxVal negated -1 == SmallInteger minVal). |
273 |
self assert:(SmallInteger minVal negated negated class == SmallInteger). |
|
1596 | 274 |
|
275 |
"Modified: / 28-02-2017 / 16:42:04 / cg" |
|
310 | 276 |
! ! |
277 |
||
278 |
!SmallIntegerTest methodsFor:'tests-class protocol'! |
|
279 |
||
280 |
testBasicNew |
|
1447 | 281 |
self should: [SmallInteger basicNew] raise: TestResult error. |
310 | 282 |
! |
283 |
||
284 |
testMaxVal |
|
285 |
"/ the original code did not check for pointer-size; |
|
286 |
||
287 |
Smalltalk isSmalltalkX ifTrue:[ |
|
1447 | 288 |
SmallInteger maxBytes == 4 ifTrue:[ |
289 |
self should: [SmallInteger maxVal = 16r3FFFFFFF]. |
|
290 |
self should: [SmallInteger maxVal == 16r3FFFFFFF]. |
|
291 |
] ifFalse:[ |
|
292 |
self should: [SmallInteger maxVal = 16r3FFFFFFFFFFFFFFF]. |
|
293 |
self should: [SmallInteger maxVal == 16r3FFFFFFFFFFFFFFF]. |
|
294 |
]. |
|
310 | 295 |
] ifFalse:[ |
1447 | 296 |
self should: [SmallInteger maxVal = 16r3FFFFFFF]. |
310 | 297 |
] |
298 |
! |
|
299 |
||
1347 | 300 |
testMaxValPointerSizeConsistency |
301 |
SmallInteger maxBytes == 4 ifTrue:[ |
|
1447 | 302 |
self assert: ((SmallInteger maxBits == 31) or:[SmallInteger maxBits == 32]). |
303 |
self assert: (ExternalAddress pointerSize == 4). |
|
1347 | 304 |
] ifFalse:[ |
1447 | 305 |
self assert: ((SmallInteger maxBits == 63) or:[SmallInteger maxBits == 64]). |
306 |
self assert: (ExternalAddress pointerSize == 8). |
|
1347 | 307 |
] |
308 |
! |
|
309 |
||
310 | 310 |
testMinVal |
311 |
"/ the original code did not check for pointer-size; |
|
312 |
||
313 |
Smalltalk isSmalltalkX ifTrue:[ |
|
1709 | 314 |
SmallInteger maxBytes == 4 ifTrue:[ |
315 |
self should: [SmallInteger minVal = 16r-40000000]. |
|
316 |
self should: [SmallInteger minVal == 16r-40000000]. |
|
317 |
] ifFalse:[ |
|
318 |
self should: [SmallInteger minVal = 16r-4000000000000000]. |
|
319 |
self should: [SmallInteger minVal == 16r-4000000000000000]. |
|
320 |
]. |
|
310 | 321 |
] ifFalse:[ |
1709 | 322 |
self should: [SmallInteger minVal = 16r-40000000]. |
310 | 323 |
] |
1709 | 324 |
|
325 |
"Modified (format): / 19-09-2017 / 16:29:45 / stefan" |
|
310 | 326 |
! |
327 |
||
328 |
testNew |
|
1447 | 329 |
self should: [SmallInteger new] raise: TestResult error. |
310 | 330 |
! ! |
331 |
||
332 |
!SmallIntegerTest class methodsFor:'documentation'! |
|
333 |
||
334 |
version |
|
335 |
^ '$Header$' |
|
336 |
! ! |
|
1074 | 337 |