author | Claus Gittinger <cg@exept.de> |
Wed, 09 Jun 1999 17:47:46 +0200 | |
changeset 32 | 03d8794d981d |
parent 31 | 4738d31a625e |
child 33 | f7b691b71cad |
permissions | -rw-r--r-- |
2 | 1 |
Object subclass:#IntegerTest |
27 | 2 |
instanceVariableNames:'' |
3 |
classVariableNames:'' |
|
4 |
poolDictionaries:'' |
|
5 |
category:'Tests - Numbers' |
|
2 | 6 |
! |
7 |
||
8 |
||
4 | 9 |
!IntegerTest class methodsFor:'misc'! |
10 |
||
31 | 11 |
testMul0_a:arg |
12 |
^ arg * 0 |
|
13 |
||
14 |
" |
|
15 |
(self testMul0_a:0) == 0 |
|
16 |
(self testMul0_a:1) == 0 |
|
17 |
(self testMul0_a:SmallInteger maxVal) == 0 |
|
18 |
(self testMul0_a:SmallInteger minVal) == 0 |
|
19 |
" |
|
20 |
||
21 |
"Created: / 9.6.1999 / 15:50:48 / cg" |
|
22 |
! |
|
23 |
||
24 |
testMul1_a:arg |
|
25 |
^ arg * 1 |
|
26 |
||
27 |
" |
|
28 |
(self testMul1_a:0) == 0 |
|
29 |
(self testMul1_a:1) == 1 |
|
30 |
(self testMul1_a:SmallInteger maxVal) == SmallInteger maxVal |
|
31 |
(self testMul1_a:SmallInteger minVal) == SmallInteger minVal |
|
32 |
" |
|
33 |
||
34 |
"Created: / 9.6.1999 / 15:49:09 / cg" |
|
35 |
! |
|
36 |
||
32 | 37 |
testMul2_a:arg |
38 |
^ arg * 2 |
|
39 |
||
40 |
" |
|
41 |
(self testMul2_a:0) == 0 |
|
42 |
(self testMul2_a:1) == 2 |
|
43 |
(self testMul2_a:SmallInteger maxVal) = (SmallInteger maxVal + SmallInteger maxVal) |
|
44 |
(self testMul2_a:SmallInteger minVal) = (SmallInteger minVal + SmallInteger minVal) |
|
45 |
" |
|
46 |
||
47 |
"Modified: / 9.6.1999 / 16:57:20 / cg" |
|
48 |
! |
|
49 |
||
50 |
testMul3_a:arg |
|
51 |
^ arg * 3 |
|
52 |
||
53 |
" |
|
54 |
(self testMul3_a:0) == 0 |
|
55 |
(self testMul3_a:1) == 3 |
|
56 |
(self testMul3_a:-1) == -3 |
|
57 |
(self testMul3_a:10000) == 30000 |
|
58 |
(self testMul3_a:SmallInteger maxVal) = (SmallInteger maxVal + SmallInteger maxVal + SmallInteger maxVal) |
|
59 |
(self testMul3_a:SmallInteger minVal) = (SmallInteger minVal + SmallInteger minVal + SmallInteger minVal) |
|
60 |
" |
|
61 |
||
62 |
"Created: / 9.6.1999 / 16:57:47 / cg" |
|
63 |
"Modified: / 9.6.1999 / 17:35:34 / cg" |
|
64 |
! |
|
65 |
||
66 |
testMul4_a:arg |
|
67 |
^ arg * 4 |
|
68 |
||
69 |
" |
|
70 |
(self testMul4_a:0) == 0 |
|
71 |
(self testMul4_a:1) == 4 |
|
72 |
(self testMul4_a:-1) == -4 |
|
73 |
(self testMul4_a:10000) == 40000 |
|
74 |
(self testMul4_a:SmallInteger maxVal//4) == 4611686018427387900 |
|
75 |
(self testMul4_a:SmallInteger maxVal//4+1) = 4611686018427387904 |
|
76 |
" |
|
77 |
||
78 |
"Created: / 9.6.1999 / 16:57:47 / cg" |
|
79 |
"Modified: / 9.6.1999 / 17:37:36 / cg" |
|
80 |
! |
|
81 |
||
82 |
testMul5_a:arg |
|
83 |
^ arg * 5 |
|
84 |
||
85 |
" |
|
86 |
(self testMul5_a:0) == 0 |
|
87 |
(self testMul5_a:1) == 5 |
|
88 |
(self testMul5_a:-1) == -5 |
|
89 |
(self testMul5_a:10000) == 50000 |
|
90 |
(self testMul5_a:SmallInteger maxVal//5) == 4611686018427387900 |
|
91 |
(self testMul5_a:SmallInteger maxVal//4+1) = 4611686018427387905 |
|
92 |
" |
|
93 |
||
94 |
"Created: / 9.6.1999 / 17:38:17 / cg" |
|
95 |
! |
|
96 |
||
31 | 97 |
testMulM1_a:arg |
98 |
^ arg * -1 |
|
99 |
||
100 |
" |
|
101 |
(self testMulM1_a:0) == 0 |
|
102 |
(self testMulM1_a:1) == -1 |
|
32 | 103 |
(self testMulM1_a:SmallInteger maxVal) == (SmallInteger minVal + 1) |
104 |
(self testMulM1_a:SmallInteger minVal) = (SmallInteger maxVal + 1) |
|
31 | 105 |
" |
106 |
||
32 | 107 |
"Modified: / 9.6.1999 / 16:54:02 / cg" |
31 | 108 |
! |
109 |
||
4 | 110 |
testPlus1_a:arg |
111 |
^ arg + 1 |
|
112 |
||
113 |
" |
|
114 |
(self testPlus1_a:SmallInteger maxVal) = 1073741824 |
|
115 |
" |
|
116 |
! |
|
117 |
||
118 |
testPlus1_b:arg |
|
119 |
^ arg perform:#+ with:1 |
|
120 |
||
121 |
" |
|
122 |
(self testPlus1_b:SmallInteger maxVal) == 1073741824 |
|
123 |
" |
|
124 |
! ! |
|
125 |
||
3 | 126 |
!IntegerTest class methodsFor:'private'! |
2 | 127 |
|
19 | 128 |
num_00000000000007FFF |
129 |
^ 16r00000000000007FFF |
|
130 |
||
131 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
132 |
"Created: / 4.6.1999 / 15:34:12 / cg" |
|
133 |
! |
|
134 |
||
135 |
num_00000000000008000 |
|
136 |
^ 16r00000000000008000 |
|
137 |
||
138 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
139 |
"Created: / 4.6.1999 / 15:39:32 / cg" |
|
140 |
! |
|
141 |
||
142 |
num_0000000000000FFFF |
|
143 |
^ 16r0000000000000FFFF |
|
144 |
||
145 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
146 |
"Created: / 4.6.1999 / 15:34:26 / cg" |
|
147 |
! |
|
148 |
||
149 |
num_00000000000010000 |
|
150 |
^ 16r00000000000010000 |
|
151 |
||
152 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
153 |
"Created: / 4.6.1999 / 15:34:31 / cg" |
|
154 |
! |
|
155 |
||
156 |
num_00000000000100000 |
|
157 |
^ 16r00000000000100000 |
|
158 |
||
159 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
160 |
"Created: / 4.6.1999 / 15:34:36 / cg" |
|
161 |
! |
|
162 |
||
163 |
num_000000000007FFFFF |
|
164 |
^ 16r000000000007FFFFF |
|
165 |
||
166 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
167 |
"Created: / 4.6.1999 / 15:37:48 / cg" |
|
168 |
! |
|
169 |
||
170 |
num_00000000000800000 |
|
171 |
^ 16r00000000000800000 |
|
172 |
||
173 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
174 |
"Created: / 4.6.1999 / 15:39:43 / cg" |
|
175 |
! |
|
176 |
||
177 |
num_00000000000FFFFFF |
|
178 |
^ 16r00000000000FFFFFF |
|
179 |
||
180 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
181 |
"Created: / 4.6.1999 / 15:37:52 / cg" |
|
182 |
! |
|
183 |
||
184 |
num_00000000001000000 |
|
185 |
^ 16r00000000001000000 |
|
186 |
||
187 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
188 |
"Created: / 4.6.1999 / 15:34:42 / cg" |
|
189 |
! |
|
190 |
||
22 | 191 |
num_0000000000FFF0000 |
192 |
^ 16r0000000000FFF0000 |
|
193 |
||
194 |
"self num_0000000000FFF0000 hexPrintString" |
|
195 |
||
196 |
"Created: / 4.6.1999 / 17:44:26 / cg" |
|
197 |
"Modified: / 4.6.1999 / 18:40:47 / cg" |
|
198 |
! |
|
199 |
||
19 | 200 |
num_00000000010000000 |
201 |
^ 16r00000000010000000 |
|
202 |
||
203 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
204 |
"Created: / 4.6.1999 / 15:34:46 / cg" |
|
205 |
! |
|
206 |
||
207 |
num_0000000007FFFFFFF |
|
208 |
^ 16r0000000007FFFFFFF |
|
209 |
||
210 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
211 |
"Created: / 4.6.1999 / 15:37:31 / cg" |
|
212 |
! |
|
213 |
||
214 |
num_00000000080000000 |
|
215 |
^ 16r00000000080000000 |
|
216 |
||
217 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
218 |
"Created: / 4.6.1999 / 15:39:56 / cg" |
|
219 |
! |
|
220 |
||
221 |
num_000000000FFFFFFFF |
|
222 |
^ 16r000000000FFFFFFFF |
|
223 |
||
224 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
225 |
"Created: / 4.6.1999 / 15:36:16 / cg" |
|
226 |
! |
|
227 |
||
228 |
num_00000000100000000 |
|
229 |
^ 16r00000000100000000 |
|
230 |
||
231 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
232 |
"Created: / 4.6.1999 / 15:34:51 / cg" |
|
233 |
! |
|
234 |
||
235 |
num_00000001000000000 |
|
236 |
^ 16r00000001000000000 |
|
237 |
||
238 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
239 |
"Created: / 4.6.1999 / 15:34:57 / cg" |
|
240 |
! |
|
241 |
||
21 | 242 |
num_0000000FFFFFFFFFF |
243 |
^ 16r0000000FFFFFFFFFF |
|
244 |
||
245 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
246 |
"Created: / 4.6.1999 / 17:41:08 / cg" |
|
247 |
! |
|
248 |
||
19 | 249 |
num_00000010000000000 |
250 |
^ 16r00000010000000000 |
|
251 |
||
252 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
253 |
"Created: / 4.6.1999 / 15:35:03 / cg" |
|
254 |
! |
|
255 |
||
256 |
num_00000100000000000 |
|
257 |
^ 16r00000100000000000 |
|
258 |
||
259 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
260 |
"Created: / 4.6.1999 / 15:35:07 / cg" |
|
261 |
! |
|
262 |
||
21 | 263 |
num_00000FFFFFFFFFF00 |
264 |
^ 16r00000FFFFFFFFFF00 |
|
265 |
||
266 |
"self num_00000FFFFFFFFFF00" |
|
267 |
||
268 |
"Created: / 4.6.1999 / 17:44:26 / cg" |
|
269 |
"Modified: / 4.6.1999 / 17:46:20 / cg" |
|
270 |
! |
|
271 |
||
272 |
num_00000FFFFFFFFFF80 |
|
273 |
^ 16r00000FFFFFFFFFF80 |
|
274 |
||
275 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
276 |
"Created: / 4.6.1999 / 17:44:23 / cg" |
|
277 |
! |
|
278 |
||
279 |
num_00000FFFFFFFFFFC0 |
|
280 |
^ 16r00000FFFFFFFFFFC0 |
|
281 |
||
282 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
283 |
"Created: / 4.6.1999 / 17:44:20 / cg" |
|
284 |
! |
|
285 |
||
286 |
num_00000FFFFFFFFFFE0 |
|
287 |
^ 16r00000FFFFFFFFFFE0 |
|
288 |
||
289 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
290 |
"Created: / 4.6.1999 / 17:44:16 / cg" |
|
291 |
! |
|
292 |
||
293 |
num_00000FFFFFFFFFFF0 |
|
294 |
^ 16r00000FFFFFFFFFFF0 |
|
295 |
||
296 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
297 |
"Created: / 4.6.1999 / 17:44:12 / cg" |
|
298 |
! |
|
299 |
||
300 |
num_00000FFFFFFFFFFF8 |
|
301 |
^ 16r00000FFFFFFFFFFF8 |
|
302 |
||
303 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
304 |
"Created: / 4.6.1999 / 17:44:09 / cg" |
|
305 |
! |
|
306 |
||
307 |
num_00000FFFFFFFFFFFC |
|
308 |
^ 16r00000FFFFFFFFFFFC |
|
309 |
||
310 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
311 |
"Created: / 4.6.1999 / 17:44:05 / cg" |
|
312 |
! |
|
313 |
||
314 |
num_00000FFFFFFFFFFFE |
|
315 |
^ 16r00000FFFFFFFFFFFE |
|
316 |
||
317 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
318 |
"Created: / 4.6.1999 / 17:45:12 / cg" |
|
319 |
! |
|
320 |
||
321 |
num_00000FFFFFFFFFFFF |
|
322 |
^ 16r00000FFFFFFFFFFFF |
|
323 |
||
324 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
325 |
"Created: / 4.6.1999 / 17:41:22 / cg" |
|
326 |
! |
|
327 |
||
19 | 328 |
num_00001000000000000 |
329 |
^ 16r00001000000000000 |
|
330 |
||
331 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
332 |
"Created: / 4.6.1999 / 15:35:13 / cg" |
|
333 |
! |
|
334 |
||
335 |
num_00010000000000000 |
|
336 |
^ 16r00010000000000000 |
|
337 |
||
338 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
339 |
"Created: / 4.6.1999 / 15:35:18 / cg" |
|
340 |
! |
|
341 |
||
21 | 342 |
num_000FFFFFFFFFFFFFF |
343 |
^ 16r000FFFFFFFFFFFFFF |
|
344 |
||
345 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
346 |
"Created: / 4.6.1999 / 17:41:26 / cg" |
|
347 |
! |
|
348 |
||
19 | 349 |
num_00100000000000000 |
350 |
^ 16r00100000000000000 |
|
351 |
||
352 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
353 |
"Created: / 4.6.1999 / 15:35:22 / cg" |
|
354 |
! |
|
355 |
||
356 |
num_01000000000000000 |
|
357 |
^ 16r01000000000000000 |
|
358 |
||
359 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
360 |
"Created: / 4.6.1999 / 15:35:27 / cg" |
|
361 |
! |
|
362 |
||
21 | 363 |
num_0FFFFFFFFFFFFFFFF |
364 |
^ 16r0FFFFFFFFFFFFFFFF |
|
365 |
||
366 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
367 |
"Created: / 4.6.1999 / 17:41:30 / cg" |
|
368 |
! |
|
369 |
||
19 | 370 |
num_10000000000000000 |
371 |
^ 16r10000000000000000 |
|
372 |
||
373 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
374 |
"Created: / 4.6.1999 / 15:35:32 / cg" |
|
375 |
! |
|
376 |
||
21 | 377 |
num_1FFFFFFFFFFFFFFFF |
378 |
^ 16r1FFFFFFFFFFFFFFFF |
|
379 |
||
380 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
381 |
"Created: / 4.6.1999 / 17:41:51 / cg" |
|
382 |
! |
|
383 |
||
384 |
num_20000000000000000 |
|
385 |
^ 16r20000000000000000 |
|
386 |
||
387 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
388 |
"Created: / 4.6.1999 / 17:40:26 / cg" |
|
389 |
! |
|
390 |
||
391 |
num_3FFFFFFFFFFFFFFFF |
|
392 |
^ 16r3FFFFFFFFFFFFFFFF |
|
393 |
||
394 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
395 |
"Created: / 4.6.1999 / 17:42:07 / cg" |
|
396 |
! |
|
397 |
||
398 |
num_40000000000000000 |
|
399 |
^ 16r40000000000000000 |
|
400 |
||
401 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
402 |
"Created: / 4.6.1999 / 17:40:29 / cg" |
|
403 |
! |
|
404 |
||
405 |
num_7FFFFFFFFFFFFFFFF |
|
406 |
^ 16r7FFFFFFFFFFFFFFFF |
|
407 |
||
408 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
409 |
"Created: / 4.6.1999 / 17:42:24 / cg" |
|
410 |
! |
|
411 |
||
412 |
num_80000000000000000 |
|
413 |
^ 16r80000000000000000 |
|
414 |
||
415 |
"Modified: / 4.6.1999 / 15:29:31 / cg" |
|
416 |
"Created: / 4.6.1999 / 17:40:33 / cg" |
|
417 |
! |
|
418 |
||
20 | 419 |
num_smallInt_maxVal |
420 |
^ SmallInteger maxVal |
|
421 |
||
21 | 422 |
"self num_smallInt_maxVal" |
423 |
||
424 |
"Modified: / 4.6.1999 / 17:33:22 / cg" |
|
20 | 425 |
! |
426 |
||
427 |
num_smallInt_minVal |
|
428 |
^ SmallInteger minVal |
|
429 |
||
21 | 430 |
"self num_smallInt_minVal" |
431 |
||
20 | 432 |
"Created: / 4.6.1999 / 16:26:05 / cg" |
21 | 433 |
"Modified: / 4.6.1999 / 17:34:31 / cg" |
20 | 434 |
! |
435 |
||
2 | 436 |
test:aBlock |
3 | 437 |
aBlock value == true ifFalse:[ |
2 | 438 |
self halt:'test failed' |
439 |
] |
|
440 |
! ! |
|
441 |
||
442 |
!IntegerTest class methodsFor:'tests'! |
|
443 |
||
444 |
test1 |
|
10 | 445 |
"general conversion & arithmetic tests. |
446 |
Notice, the arithmetic tests are both performed via regular sends |
|
447 |
and via constructed performs. The reason is to test both inlined |
|
448 |
JIT-compiler code AND the regular methods code." |
|
2 | 449 |
|
3 | 450 |
|minVal maxVal maxValPlus1 minValMinus1 halfMin halfMax t t1 t2| |
451 |
||
452 |
minVal := SmallInteger perform:('minVal' asSymbol). |
|
453 |
maxVal := SmallInteger perform:('maxVal' asSymbol). |
|
454 |
||
20 | 455 |
self test:[minVal == self num_smallInt_minVal]. |
456 |
self test:[maxVal == self num_smallInt_maxVal]. |
|
457 |
||
3 | 458 |
self test:[minVal == SmallInteger minVal]. |
459 |
self test:[maxVal == SmallInteger maxVal]. |
|
2 | 460 |
|
9 | 461 |
t := SmallInteger perform:('maxBytes' asSymbol). |
462 |
self test:[t == SmallInteger maxBytes]. |
|
463 |
t := SmallInteger perform:('maxBits' asSymbol). |
|
464 |
self test:[t == SmallInteger maxBits]. |
|
465 |
||
7 | 466 |
self testPrinting1. |
2 | 467 |
|
468 |
SmallInteger maxBytes == 4 ifTrue:[ |
|
3 | 469 |
self test:[minVal hexPrintString = '-40000000']. |
470 |
self test:[maxVal hexPrintString = '3FFFFFFF']. |
|
471 |
self test:[minVal == -1073741824]. |
|
472 |
self test:[maxVal == 1073741823]. |
|
2 | 473 |
maxValPlus1 := 1073741824. |
474 |
minValMinus1 := -1073741825. |
|
475 |
self test:[minValMinus1 hexPrintString = '-40000001']. |
|
476 |
self test:[maxValPlus1 hexPrintString = '40000000']. |
|
3 | 477 |
halfMin := -16r20000000. |
478 |
halfMax := 16r20000000. |
|
2 | 479 |
]. |
480 |
SmallInteger maxBytes == 8 ifTrue:[ |
|
3 | 481 |
self test:[minVal hexPrintString = '-4000000000000000']. |
482 |
self test:[maxVal hexPrintString = '3FFFFFFFFFFFFFFF']. |
|
483 |
self test:[minVal == -4611686018427387904]. |
|
484 |
self test:[maxVal == 4611686018427387903]. |
|
2 | 485 |
maxValPlus1 := 4611686018427387904. |
486 |
minValMinus1 := -4611686018427387905. |
|
487 |
self test:[minValMinus1 hexPrintString = '-4000000000000001']. |
|
488 |
self test:[maxValPlus1 hexPrintString = '4000000000000000']. |
|
3 | 489 |
halfMin := -16r2000000000000000. |
490 |
halfMax := 16r2000000000000000. |
|
2 | 491 |
]. |
492 |
||
493 |
"arithmetic overFlow checks" |
|
494 |
||
4 | 495 |
"/ self test:[(maxVal + 1) inspect.maxValPlus1 inspect. true]. |
6 | 496 |
self test:[(maxVal perform:'+' asSymbol with:1) = maxValPlus1]. |
497 |
self test:[(maxVal + 1) = maxValPlus1]. |
|
498 |
self test:[(minVal perform:'-' asSymbol with:1) = minValMinus1]. |
|
499 |
self test:[(minVal - 1) = minValMinus1]. |
|
3 | 500 |
|
6 | 501 |
self test:[(halfMax perform:'+' asSymbol with:halfMax) = maxValPlus1]. |
3 | 502 |
self test:[(halfMax + halfMax) = maxValPlus1]. |
6 | 503 |
self test:[(halfMin perform:'+' asSymbol with:halfMin) == minVal]. |
3 | 504 |
self test:[(halfMin + halfMin) == minVal]. |
6 | 505 |
self test:[(halfMax perform:'*' asSymbol with:2) = maxValPlus1]. |
3 | 506 |
self test:[(halfMax * 2) = maxValPlus1]. |
6 | 507 |
self test:[(halfMin perform:'*' asSymbol with:2) == minVal]. |
3 | 508 |
self test:[(halfMin * 2) == minVal]. |
6 | 509 |
self test:[(maxValPlus1 perform:'//' asSymbol with:2) == halfMax]. |
510 |
self test:[(maxValPlus1 // 2) == halfMax]. |
|
511 |
self test:[(halfMax perform:'bitShift:' asSymbol with:1) = maxValPlus1]. |
|
512 |
self test:[(halfMin perform:'bitShift:' asSymbol with:1) == minVal]. |
|
3 | 513 |
self test:[(halfMax bitShift:1) = maxValPlus1]. |
514 |
self test:[(halfMin bitShift:1) == minVal]. |
|
515 |
||
516 |
"LargeInt op -> SmallInt result" |
|
517 |
t := maxVal + 1. |
|
518 |
self test:[t - 1 == maxVal]. |
|
519 |
t := minVal - 1. |
|
520 |
self test:[t + 1 == minVal]. |
|
521 |
||
27 | 522 |
self testSmallIntegerArithmetic. |
19 | 523 |
self testLiteralNumbers. |
15 | 524 |
self testLargeAddition. |
12
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
525 |
self testLargeMultiplication. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
526 |
self testLargeDivision. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
527 |
|
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
528 |
" |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
529 |
self test1 |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
530 |
" |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
531 |
|
27 | 532 |
"Modified: / 6.6.1999 / 14:46:11 / cg" |
12
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
533 |
! |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
534 |
|
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
535 |
testLargeAddition |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
536 |
"general conversion & arithmetic tests. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
537 |
Notice, the arithmetic tests are both performed via regular sends |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
538 |
and via constructed performs. The reason is to test both inlined |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
539 |
JIT-compiler code AND the regular methods code." |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
540 |
|
19 | 541 |
|s n1 n2 x| |
13 | 542 |
|
23 | 543 |
"Large + Large addition" |
544 |
self testReading1. |
|
545 |
||
546 |
self test:[(20 factorial + 20 factorial) printString = '4865804016353280000']. |
|
547 |
self test:[(20 factorial + 1) printString = '2432902008176640001']. |
|
548 |
self test:[(20 factorial + 1000) printString = '2432902008176641000']. |
|
549 |
||
29 | 550 |
"Large + Small addition" |
551 |
||
552 |
n1 := 16r3FFFFFFF. n2 := 1. |
|
553 |
self test:[(n1 + n2 ) hexPrintString = '40000000']. |
|
554 |
self test:[(n1 perform:'+' asSymbol with:n2 ) hexPrintString = '40000000']. |
|
555 |
n1 := 16r3FFFFFFFF. n2 := 1. |
|
556 |
self test:[(n1 + n2 ) hexPrintString = '400000000']. |
|
557 |
self test:[(n1 perform:'+' asSymbol with:n2 ) hexPrintString = '400000000']. |
|
558 |
n1 := 16r3FFFFFFFFF. n2 := 1. |
|
559 |
self test:[(n1 + n2 ) hexPrintString = '4000000000']. |
|
560 |
self test:[(n1 perform:'+' asSymbol with:n2 ) hexPrintString = '4000000000']. |
|
561 |
n1 := 16r3FFFFFFFFFF. n2 := 1. |
|
562 |
self test:[(n1 + n2 ) hexPrintString = '40000000000']. |
|
563 |
self test:[(n1 perform:'+' asSymbol with:n2 ) hexPrintString = '40000000000']. |
|
564 |
n1 := 16r3FFFFFFFFFFF. n2 := 1. |
|
565 |
self test:[(n1 + n2 ) hexPrintString = '400000000000']. |
|
566 |
self test:[(n1 perform:'+' asSymbol with:n2 ) hexPrintString = '400000000000']. |
|
567 |
n1 := 16r3FFFFFFFFFFFF. n2 := 1. |
|
568 |
self test:[(n1 + n2 ) hexPrintString = '4000000000000']. |
|
569 |
self test:[(n1 perform:'+' asSymbol with:n2 ) hexPrintString = '4000000000000']. |
|
570 |
n1 := 16r3FFFFFFFFFFFFF. n2 := 1. |
|
571 |
self test:[(n1 + n2 ) hexPrintString = '40000000000000']. |
|
572 |
self test:[(n1 perform:'+' asSymbol with:n2 ) hexPrintString = '40000000000000']. |
|
573 |
n1 := 16r3FFFFFFFFFFFFFF. n2 := 1. |
|
574 |
self test:[(n1 + n2 ) hexPrintString = '400000000000000']. |
|
575 |
self test:[(n1 perform:'+' asSymbol with:n2 ) hexPrintString = '400000000000000']. |
|
576 |
n1 := 16r3FFFFFFFFFFFFFFF. n2 := 1. |
|
577 |
self test:[(n1 + n2 ) hexPrintString = '4000000000000000']. |
|
578 |
self test:[(n1 perform:'+' asSymbol with:n2 ) hexPrintString = '4000000000000000']. |
|
579 |
||
580 |
"Large + Large addition" |
|
23 | 581 |
|
582 |
n1 := 16r100000000. n2 := 16r7FFFFFFF. |
|
583 |
self test:[(n1 - n2 ) hexPrintString = '80000001']. |
|
584 |
self test:[(16r100000000 - n2 ) hexPrintString = '80000001']. |
|
585 |
self test:[(n1 - 16r7FFFFFFF ) hexPrintString = '80000001']. |
|
586 |
self test:[(16r100000000 - 16r7FFFFFFF ) hexPrintString = '80000001']. |
|
587 |
self test:[(n1 perform:'-' asSymbol with:n2 ) hexPrintString = '80000001']. |
|
588 |
self test:[(16r100000000 perform:'-' asSymbol with:n2 ) hexPrintString = '80000001']. |
|
589 |
self test:[(n1 perform:'-' asSymbol with:16r7FFFFFFF ) hexPrintString = '80000001']. |
|
590 |
self test:[(16r100000000 perform:'-' asSymbol with:16r7FFFFFFF ) hexPrintString = '80000001']. |
|
591 |
||
592 |
n1 := 16r100000000. n2 := 16r80000000. |
|
593 |
self test:[(n1 - n2 ) hexPrintString = '80000000']. |
|
594 |
self test:[(16r100000000 - n2 ) hexPrintString = '80000000']. |
|
595 |
self test:[(n1 - 16r80000000 ) hexPrintString = '80000000']. |
|
596 |
self test:[(16r100000000 - 16r80000000 ) hexPrintString = '80000000']. |
|
597 |
self test:[(n1 perform:'-' asSymbol with:n2 ) hexPrintString = '80000000']. |
|
598 |
self test:[(16r100000000 perform:'-' asSymbol with:n2 ) hexPrintString = '80000000']. |
|
599 |
self test:[(n1 perform:'-' asSymbol with:16r80000000 ) hexPrintString = '80000000']. |
|
600 |
self test:[(16r100000000 perform:'-' asSymbol with:16r80000000 ) hexPrintString = '80000000']. |
|
17 | 601 |
|
602 |
n1 := 16r100000000. n2 := 16rFFFFFFFF. |
|
23 | 603 |
self test:[(n1 - n2 ) hexPrintString = '1']. |
604 |
self test:[(16r100000000 - n2 ) hexPrintString = '1']. |
|
19 | 605 |
self test:[(x := n1 - 16rFFFFFFFF) == 1]. |
17 | 606 |
|
23 | 607 |
self test:[(n1 - 16rFFFFFFFF ) hexPrintString = '1']. |
608 |
self test:[(16r100000000 - 16rFFFFFFFF ) hexPrintString = '1']. |
|
609 |
self test:[(n1 perform:'-' asSymbol with:n2 ) hexPrintString = '1']. |
|
610 |
self test:[(16r100000000 perform:'-' asSymbol with:n2 ) hexPrintString = '1']. |
|
611 |
self test:[(n1 perform:'-' asSymbol with:16rFFFFFFFF ) hexPrintString = '1']. |
|
612 |
self test:[(16r100000000 perform:'-' asSymbol with:16rFFFFFFFF ) hexPrintString = '1']. |
|
613 |
||
614 |
n1 := 16r100000000. n2 := 1. |
|
615 |
self test:[(n1 - n2) hexPrintString = 'FFFFFFFF']. |
|
616 |
self test:[(n1 - n2) hexPrintString = 'FFFFFFFF']. |
|
617 |
self test:[(16r100000000 - n2) hexPrintString = 'FFFFFFFF']. |
|
618 |
self test:[(n1 - 1) hexPrintString = 'FFFFFFFF']. |
|
619 |
self test:[(16r100000000 - 1) hexPrintString = 'FFFFFFFF']. |
|
620 |
self test:[(n1 perform:'-' asSymbol with:n2) hexPrintString = 'FFFFFFFF']. |
|
621 |
self test:[(16r100000000 perform:'-' asSymbol with:n2) hexPrintString = 'FFFFFFFF']. |
|
622 |
self test:[(n1 perform:'-' asSymbol with:1) hexPrintString = 'FFFFFFFF']. |
|
623 |
self test:[(16r100000000 perform:'-' asSymbol with:1) hexPrintString = 'FFFFFFFF']. |
|
624 |
||
625 |
n1 := 16r100000000. n2 := 16r10000000. |
|
626 |
self test:[(n1 - n2) hexPrintString = 'F0000000']. |
|
627 |
self test:[(16r100000000 - n2) hexPrintString = 'F0000000']. |
|
628 |
self test:[(n1 - 16r10000000) hexPrintString = 'F0000000']. |
|
629 |
self test:[(16r100000000 - 16r10000000) hexPrintString = 'F0000000']. |
|
630 |
self test:[(n1 perform:'-' asSymbol with:n2) hexPrintString = 'F0000000']. |
|
631 |
self test:[(16r100000000 perform:'-' asSymbol with:n2) hexPrintString = 'F0000000']. |
|
632 |
self test:[(n1 perform:'-' asSymbol with:16r10000000) hexPrintString = 'F0000000']. |
|
633 |
self test:[(16r100000000 perform:'-' asSymbol with:16r10000000) hexPrintString = 'F0000000']. |
|
634 |
||
635 |
"Large - small subtraction" |
|
636 |
self test:[(20 factorial + 20 factorial - 1) printString = '4865804016353279999']. |
|
637 |
self test:[(20 factorial - 10 factorial + 3628800) printString = '2432902008176640000']. |
|
638 |
self test:[(20 factorial - 11 factorial + 39916800) printString = '2432902008176640000']. |
|
639 |
self test:[(20 factorial - 12 factorial + 479001600) printString = '2432902008176640000']. |
|
640 |
self test:[(20 factorial - 13 factorial + 6227020800) printString = '2432902008176640000']. |
|
641 |
self test:[(20 factorial - 14 factorial + 87178291200) printString = '2432902008176640000']. |
|
642 |
self test:[(20 factorial - 15 factorial + 1307674368000) printString = '2432902008176640000']. |
|
643 |
self test:[(20 factorial - 16 factorial + 20922789888000) printString = '2432902008176640000']. |
|
644 |
self test:[(20 factorial + 10 factorial - 3628800) printString = '2432902008176640000']. |
|
12
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
645 |
|
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
646 |
" |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
647 |
self testLargeAddition |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
648 |
" |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
649 |
|
19 | 650 |
"Modified: / 4.6.1999 / 15:26:55 / cg" |
12
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
651 |
! |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
652 |
|
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
653 |
testLargeDivision |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
654 |
|t| |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
655 |
|
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
656 |
t := 20 factorial. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
657 |
|
16 | 658 |
self test:[t printString = '2432902008176640000']. |
659 |
self test:[t \\ 10 == 0]. |
|
660 |
t := t // 10. |
|
661 |
self test:[t printString = '243290200817664000']. |
|
662 |
self test:[t \\ 10 == 0]. |
|
663 |
t := t // 10. |
|
664 |
self test:[t printString = '24329020081766400']. |
|
665 |
self test:[t \\ 10 == 0]. |
|
666 |
t := t // 10. |
|
667 |
self test:[t printString = '2432902008176640']. |
|
668 |
self test:[t \\ 10 == 0]. |
|
669 |
t := t // 10. |
|
670 |
self test:[t printString = '243290200817664']. |
|
671 |
self test:[t \\ 10 == 4]. |
|
672 |
t := t // 10. |
|
673 |
self test:[t printString = '24329020081766']. |
|
674 |
self test:[t \\ 10 == 6]. |
|
675 |
t := t // 10. |
|
676 |
self test:[t printString = '2432902008176']. |
|
677 |
self test:[t \\ 10 == 6]. |
|
678 |
t := t // 10. |
|
679 |
self test:[t printString = '243290200817']. |
|
680 |
self test:[t \\ 10 == 7]. |
|
681 |
t := t // 10. |
|
682 |
self test:[t printString = '24329020081']. |
|
683 |
self test:[t \\ 10 == 1]. |
|
684 |
t := t // 10. |
|
685 |
self test:[t printString = '2432902008']. |
|
686 |
self test:[t \\ 10 == 8]. |
|
687 |
t := t // 10. |
|
688 |
self test:[t printString = '243290200']. |
|
689 |
self test:[t \\ 10 == 0]. |
|
690 |
||
691 |
||
692 |
t := 20 factorial. |
|
693 |
||
694 |
self test:[t printString = '2432902008176640000']. |
|
695 |
self test:[t \\ 1000 == 0]. |
|
696 |
t := t // 1000. |
|
697 |
self test:[t printString = '2432902008176640']. |
|
698 |
self test:[t \\ 1000 == 640]. |
|
699 |
t := t // 1000. |
|
700 |
self test:[t printString = '2432902008176']. |
|
701 |
self test:[t \\ 1000 == 176]. |
|
702 |
t := t // 1000. |
|
703 |
self test:[t printString = '2432902008']. |
|
704 |
self test:[t \\ 1000 == 8]. |
|
705 |
t := t // 1000. |
|
706 |
self test:[t printString = '2432902']. |
|
707 |
self test:[t \\ 1000 == 902]. |
|
708 |
t := t // 1000. |
|
709 |
self test:[t printString = '2432']. |
|
710 |
self test:[t \\ 1000 == 432]. |
|
711 |
t := t // 1000. |
|
712 |
self test:[t == 2]. |
|
713 |
self test:[t \\ 1000 == 2]. |
|
714 |
||
715 |
||
716 |
t := 20 factorial. |
|
717 |
||
12
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
718 |
"Large // SmallInt division" |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
719 |
t := t // 20. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
720 |
self test:[t printString = 19 factorial printString]. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
721 |
t := t // 19. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
722 |
self test:[t printString = 18 factorial printString]. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
723 |
t := t // 18. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
724 |
self test:[t printString = 17 factorial printString]. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
725 |
t := t // 17. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
726 |
self test:[t printString = 16 factorial printString]. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
727 |
t := t // 16. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
728 |
self test:[t printString = 15 factorial printString]. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
729 |
t := t // 15. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
730 |
self test:[t printString = 14 factorial printString]. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
731 |
t := t // 14. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
732 |
self test:[t printString = 13 factorial printString]. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
733 |
t := t // 13. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
734 |
self test:[t printString = 12 factorial printString]. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
735 |
t := t // 12. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
736 |
self test:[t printString = 11 factorial printString]. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
737 |
t := t // 11. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
738 |
self test:[t printString = 10 factorial printString]. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
739 |
self test:[t == 10 factorial]. |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
740 |
|
26 | 741 |
t := 20 factorial. |
742 |
t := t + 21 factorial. |
|
743 |
t absSubtract:21 factorial. |
|
744 |
self test:[t compressed = 20 factorial]. |
|
745 |
||
746 |
self test:[|v| |
|
747 |
v := 100 factorial copy. |
|
748 |
v absSubtract:99 factorial. |
|
749 |
v compressed = (100 factorial - 99 factorial)]. |
|
750 |
||
12
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
751 |
"Large // Large division" |
26 | 752 |
self test:[(20 factorial // 19 factorial) == 20]. |
753 |
self test:[(20 factorial * 21 // 20 // 21) = (19 factorial)]. |
|
754 |
self test:[(10000 factorial // 9999 factorial) == 10000]. |
|
755 |
self test:[(10000 factorial // 9999 factorial) == (10000 factorial / 9999 factorial)]. |
|
12
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
756 |
|
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
757 |
" |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
758 |
self testLargeDivision |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
759 |
" |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
760 |
|
26 | 761 |
"Modified: / 4.6.1999 / 23:54:57 / cg" |
12
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
762 |
! |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
763 |
|
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
764 |
testLargeMultiplication |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
765 |
|t1| |
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
766 |
|
3 | 767 |
"multiplication" |
768 |
t1 := 100. |
|
769 |
self test:[t1 * t1 == 10000]. |
|
10 | 770 |
self test:[(t1 perform:'*' asSymbol with:t1) == 10000]. |
11 | 771 |
self test:[(t1 * t1) printString = '10000']. |
772 |
self test:[(t1 perform:'*' asSymbol with:t1) printString = '10000']. |
|
773 |
||
3 | 774 |
t1 := 1000. |
775 |
self test:[t1 * t1 == 1000000]. |
|
10 | 776 |
self test:[(t1 perform:'*' asSymbol with:t1) == 1000000]. |
11 | 777 |
self test:[(t1 * t1) printString = '1000000']. |
778 |
self test:[(t1 perform:'*' asSymbol with:t1) printString = '1000000']. |
|
779 |
||
3 | 780 |
t1 := 10000. |
781 |
self test:[t1 * t1 == 100000000]. |
|
10 | 782 |
self test:[(t1 perform:'*' asSymbol with:t1) == 100000000]. |
11 | 783 |
self test:[(t1 * t1) printString = '100000000']. |
784 |
self test:[(t1 perform:'*' asSymbol with:t1) printString = '100000000']. |
|
785 |
||
3 | 786 |
t1 := 100000. |
787 |
SmallInteger maxBytes == 4 ifTrue:[ |
|
10 | 788 |
self test:[t1 * t1 = 10000000000]. |
789 |
self test:[(t1 perform:'*' asSymbol with:t1) = 10000000000]. |
|
3 | 790 |
]. |
791 |
SmallInteger maxBytes == 8 ifTrue:[ |
|
792 |
self test:[t1 * t1 == 10000000000]. |
|
10 | 793 |
self test:[(t1 perform:'*' asSymbol with:t1) == 10000000000]. |
3 | 794 |
]. |
4 | 795 |
|
11 | 796 |
self test:[(t1 * t1) printString = '10000000000']. |
4 | 797 |
self test:[(t1 perform:'*' asSymbol with:t1) printString = '10000000000']. |
11 | 798 |
|
3 | 799 |
t1 := 1000000. |
800 |
self test:[(t1 * t1) printString = '1000000000000']. |
|
11 | 801 |
self test:[(t1 perform:'*' asSymbol with:t1) printString = '1000000000000']. |
802 |
||
3 | 803 |
t1 := 10000000. |
804 |
self test:[(t1 * t1) printString = '100000000000000']. |
|
11 | 805 |
self test:[(t1 perform:'*' asSymbol with:t1) printString = '100000000000000']. |
806 |
||
3 | 807 |
t1 := 100000000. |
808 |
self test:[(t1 * t1) printString = '10000000000000000']. |
|
11 | 809 |
self test:[(t1 perform:'*' asSymbol with:t1) printString = '10000000000000000']. |
810 |
||
3 | 811 |
t1 := 1000000000. |
812 |
self test:[(t1 * t1) printString = '1000000000000000000']. |
|
11 | 813 |
self test:[(t1 perform:'*' asSymbol with:t1) printString = '1000000000000000000']. |
814 |
||
2 | 815 |
|
3 | 816 |
"Large * SmallInt multiplication" |
817 |
self test:[10 factorial printString = '3628800']. |
|
818 |
self test:[20 factorial printString = '2432902008176640000']. |
|
819 |
self test:[100 factorial printString = '93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000']. |
|
820 |
self test:[1000 factorial printString = '402387260077093773543702433923003985719374864210714632543799910429938512398629020592044208486969404800479988610197196058631666872994808558901323829669944590997424504087073759918823627727188732519779505950995276120874975462497043601418278094646496291056393887437886487337119181045825783647849977012476632889835955735432513185323958463075557409114262417474349347553428646576611667797396668820291207379143853719588249808126867838374559731746136085379534524221586593201928090878297308431392844403281231558611036976801357304216168747609675871348312025478589320767169132448426236131412508780208000261683151027341827977704784635868170164365024153691398281264810213092761244896359928705114964975419909342221566832572080821333186116811553615836546984046708975602900950537616475847728421889679646244945160765353408198901385442487984959953319101723355556602139450399736280750137837615307127761926849034352625200015888535147331611702103968175921510907788019393178114194545257223865541461062892187960223838971476088506276862967146674697562911234082439208160153780889893964518263243671616762179168909779911903754031274622289988005195444414282012187361745992642956581746628302955570299024324153181617210465832036786906117260158783520751516284225540265170483304226143974286933061690897968482590125458327168226458066526769958652682272807075781391858178889652208164348344825993266043367660176999612831860788386150279465955131156552036093988180612138558600301435694527224206344631797460594682573103790084024432438465657245014402821885252470935190620929023136493273497565513958720559654228749774011413346962715422845862377387538230483865688976461927383814900140767310446640259899490222221765904339901886018566526485061799702356193897017860040811889729918311021171229845901641921068884387121855646124960798722908519296819372388642614839657382291123125024186649353143970137428531926649875337218940694281434118520158014123344828015051399694290153483077644569099073152433278288269864602789864321139083506217095002597389863554277196742822248757586765752344220207573630569498825087968928162753848863396909959826280956121450994871701244516461260379029309120889086942028510640182154399457156805941872748998094254742173582401063677404595741785160829230135358081840096996372524230560855903700624271243416909004153690105933983835777939410970027753472000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000']. |
|
2 | 821 |
|
3 | 822 |
"Large * Large multiplication" |
24 | 823 |
self test:[(16r3FFF * 16r3FFF) hexPrintString = 'FFF8001']. |
824 |
self test:[(16r7FFF * 16r7FFF) hexPrintString = '3FFF0001']. |
|
825 |
self test:[(16rFFFF * 16rFFFF) hexPrintString = 'FFFE0001']. |
|
826 |
self test:[(16r3FFFFF * 16r3FFFFF) hexPrintString = 'FFFFF800001']. |
|
827 |
self test:[(16r7FFFFF * 16r7FFFFF) hexPrintString = '3FFFFF000001']. |
|
828 |
self test:[(16rFFFFFF * 16rFFFFFF) hexPrintString = 'FFFFFE000001']. |
|
829 |
self test:[(16r3FFFFFFF * 16r3FFFFFFF) hexPrintString = 'FFFFFFF80000001']. |
|
830 |
self test:[(16r7FFFFFFF * 16r7FFFFFFF) hexPrintString = '3FFFFFFF00000001']. |
|
831 |
self test:[(16rFFFFFFFF * 16rFFFFFFFF) hexPrintString = 'FFFFFFFE00000001']. |
|
832 |
self test:[(16r3FFFFFFFFF * 16r3FFFFFFFFF) hexPrintString = 'FFFFFFFFF8000000001']. |
|
833 |
self test:[(16r7FFFFFFFFF * 16r7FFFFFFFFF) hexPrintString = '3FFFFFFFFF0000000001']. |
|
834 |
self test:[(16rFFFFFFFFFF * 16rFFFFFFFFFF) hexPrintString = 'FFFFFFFFFE0000000001']. |
|
3 | 835 |
self test:[(20 factorial * 20 factorial) printString = '5919012181389927685417441689600000000']. |
7 | 836 |
|
837 |
" |
|
12
29d0f2e59dcb
splitted into smaller methods to avoid JIT-bail-out
Claus Gittinger <cg@exept.de>
parents:
11
diff
changeset
|
838 |
self testLargeMultiplication |
7 | 839 |
" |
10 | 840 |
|
11 | 841 |
"Modified: / 20.5.1999 / 09:41:19 / cg" |
7 | 842 |
! |
843 |
||
19 | 844 |
testLiteralNumbers |
845 |
self test:[self num_00000000000010000 hexPrintString = '10000']. |
|
846 |
self test:[self num_00000000000100000 hexPrintString = '100000']. |
|
847 |
self test:[self num_00000000001000000 hexPrintString = '1000000']. |
|
848 |
self test:[self num_00000000010000000 hexPrintString = '10000000']. |
|
849 |
self test:[self num_00000000100000000 hexPrintString = '100000000']. |
|
850 |
self test:[self num_00000001000000000 hexPrintString = '1000000000']. |
|
851 |
self test:[self num_00000010000000000 hexPrintString = '10000000000']. |
|
852 |
self test:[self num_00000100000000000 hexPrintString = '100000000000']. |
|
853 |
self test:[self num_00001000000000000 hexPrintString = '1000000000000']. |
|
854 |
self test:[self num_00010000000000000 hexPrintString = '10000000000000']. |
|
855 |
self test:[self num_00100000000000000 hexPrintString = '100000000000000']. |
|
856 |
self test:[self num_01000000000000000 hexPrintString = '1000000000000000']. |
|
857 |
self test:[self num_10000000000000000 hexPrintString = '10000000000000000']. |
|
858 |
||
859 |
self test:[self num_00000000000007FFF hexPrintString = '7FFF']. |
|
860 |
self test:[self num_00000000000008000 hexPrintString = '8000']. |
|
861 |
self test:[self num_0000000000000FFFF hexPrintString = 'FFFF']. |
|
862 |
self test:[self num_000000000007FFFFF hexPrintString = '7FFFFF']. |
|
863 |
self test:[self num_00000000000800000 hexPrintString = '800000']. |
|
864 |
self test:[self num_00000000000FFFFFF hexPrintString = 'FFFFFF']. |
|
865 |
self test:[self num_0000000007FFFFFFF hexPrintString = '7FFFFFFF']. |
|
866 |
self test:[self num_00000000080000000 hexPrintString = '80000000']. |
|
867 |
self test:[self num_000000000FFFFFFFF hexPrintString = 'FFFFFFFF']. |
|
21 | 868 |
self test:[self num_0000000FFFFFFFFFF hexPrintString = 'FFFFFFFFFF']. |
869 |
self test:[self num_00000FFFFFFFFFFFF hexPrintString = 'FFFFFFFFFFFF']. |
|
870 |
self test:[self num_000FFFFFFFFFFFFFF hexPrintString = 'FFFFFFFFFFFFFF']. |
|
871 |
self test:[self num_0FFFFFFFFFFFFFFFF hexPrintString = 'FFFFFFFFFFFFFFFF']. |
|
872 |
self test:[self num_1FFFFFFFFFFFFFFFF hexPrintString = '1FFFFFFFFFFFFFFFF']. |
|
873 |
self test:[self num_20000000000000000 hexPrintString = '20000000000000000']. |
|
874 |
self test:[self num_3FFFFFFFFFFFFFFFF hexPrintString = '3FFFFFFFFFFFFFFFF']. |
|
875 |
self test:[self num_40000000000000000 hexPrintString = '40000000000000000']. |
|
876 |
self test:[self num_7FFFFFFFFFFFFFFFF hexPrintString = '7FFFFFFFFFFFFFFFF']. |
|
877 |
self test:[self num_80000000000000000 hexPrintString = '80000000000000000']. |
|
878 |
||
879 |
self test:[self num_00000FFFFFFFFFFFE hexPrintString = 'FFFFFFFFFFFE']. |
|
880 |
self test:[self num_00000FFFFFFFFFFFC hexPrintString = 'FFFFFFFFFFFC']. |
|
881 |
self test:[self num_00000FFFFFFFFFFF8 hexPrintString = 'FFFFFFFFFFF8']. |
|
882 |
self test:[self num_00000FFFFFFFFFFF0 hexPrintString = 'FFFFFFFFFFF0']. |
|
883 |
self test:[self num_00000FFFFFFFFFFE0 hexPrintString = 'FFFFFFFFFFE0']. |
|
884 |
self test:[self num_00000FFFFFFFFFFC0 hexPrintString = 'FFFFFFFFFFC0']. |
|
885 |
self test:[self num_00000FFFFFFFFFF80 hexPrintString = 'FFFFFFFFFF80']. |
|
886 |
self test:[self num_00000FFFFFFFFFF00 hexPrintString = 'FFFFFFFFFF00']. |
|
19 | 887 |
|
22 | 888 |
self test:[self num_0000000000FFF0000 hexPrintString = 'FFF0000']. |
889 |
||
19 | 890 |
" |
891 |
self testLiteralNumbers |
|
892 |
" |
|
893 |
||
22 | 894 |
"Modified: / 4.6.1999 / 18:41:09 / cg" |
19 | 895 |
! |
896 |
||
7 | 897 |
testPrinting1 |
898 |
self test:[10 printString = '10']. |
|
899 |
self test:[100 printString = '100']. |
|
900 |
self test:[1000 printString = '1000']. |
|
901 |
self test:[10000 printString = '10000']. |
|
902 |
self test:[100000 printString = '100000']. |
|
903 |
self test:[1000000 printString = '1000000']. |
|
904 |
self test:[10000000 printString = '10000000']. |
|
905 |
self test:[100000000 printString = '100000000']. |
|
906 |
self test:[1000000000 printString = '1000000000']. |
|
907 |
self test:[10000000000 printString = '10000000000']. |
|
908 |
self test:[100000000000 printString = '100000000000']. |
|
909 |
self test:[1000000000000 printString = '1000000000000']. |
|
910 |
self test:[10000000000000 printString = '10000000000000']. |
|
911 |
self test:[100000000000000 printString = '100000000000000']. |
|
912 |
self test:[1000000000000000 printString = '1000000000000000']. |
|
913 |
self test:[10000000000000000 printString = '10000000000000000']. |
|
914 |
self test:[100000000000000000 printString = '100000000000000000']. |
|
915 |
||
916 |
" |
|
917 |
self testPrinting1 |
|
918 |
" |
|
919 |
! |
|
920 |
||
921 |
testReading1 |
|
922 |
|t| |
|
923 |
||
5 | 924 |
self test:[(Integer readFrom:'4865804016353280000') printString = '4865804016353280000']. |
925 |
self test:[(Integer readFrom:'FFFFFFFF' radix:16) hexPrintString = 'FFFFFFFF']. |
|
926 |
self test:[(Integer readFrom:'FFFFFFFFF' radix:16) hexPrintString = 'FFFFFFFFF']. |
|
927 |
self test:[(Integer readFrom:'FFFFFFFFFF' radix:16) hexPrintString = 'FFFFFFFFFF']. |
|
928 |
self test:[(Integer readFrom:'FFFFFFFFFFF' radix:16) hexPrintString = 'FFFFFFFFFFF']. |
|
929 |
self test:[(Integer readFrom:'FFFFFFFFFFFF' radix:16) hexPrintString = 'FFFFFFFFFFFF']. |
|
15 | 930 |
self test:[(Integer readFrom:'FFFFFFFFFFFFF' radix:16) hexPrintString = 'FFFFFFFFFFFFF']. |
931 |
self test:[(Integer readFrom:'FFFFFFFFFFFFFF' radix:16) hexPrintString = 'FFFFFFFFFFFFFF']. |
|
5 | 932 |
|
933 |
self test:[(Integer readFrom:'10000000' radix:16) hexPrintString = '10000000']. |
|
934 |
self test:[(Integer readFrom:'100000000' radix:16) hexPrintString = '100000000']. |
|
935 |
self test:[(Integer readFrom:'1000000000' radix:16) hexPrintString = '1000000000']. |
|
936 |
self test:[(Integer readFrom:'10000000000' radix:16) hexPrintString = '10000000000']. |
|
937 |
self test:[(Integer readFrom:'100000000000' radix:16) hexPrintString = '100000000000']. |
|
15 | 938 |
self test:[(Integer readFrom:'1000000000000' radix:16) hexPrintString = '1000000000000']. |
939 |
self test:[(Integer readFrom:'10000000000000' radix:16) hexPrintString = '10000000000000']. |
|
5 | 940 |
|
941 |
t := Integer readFrom:'FFFFFFFF' radix:16. |
|
942 |
self test:[(t + 1) hexPrintString = '100000000']. |
|
943 |
t := Integer readFrom:'FFFFFFFFF' radix:16. |
|
944 |
self test:[(t + 1) hexPrintString = '1000000000']. |
|
945 |
t := Integer readFrom:'FFFFFFFFFF' radix:16. |
|
946 |
self test:[(t + 1) hexPrintString = '10000000000']. |
|
947 |
t := Integer readFrom:'FFFFFFFFFFF' radix:16. |
|
948 |
self test:[(t + 1) hexPrintString = '100000000000']. |
|
949 |
||
950 |
t := Integer readFrom:'10000000' radix:16. |
|
951 |
self test:[(t + 1) hexPrintString = '10000001']. |
|
952 |
t := Integer readFrom:'100000000' radix:16. |
|
953 |
self test:[(t + 1) hexPrintString = '100000001']. |
|
954 |
t := Integer readFrom:'1000000000' radix:16. |
|
955 |
self test:[(t + 1) hexPrintString = '1000000001']. |
|
956 |
t := Integer readFrom:'10000000000' radix:16. |
|
957 |
self test:[(t + 1) hexPrintString = '10000000001']. |
|
958 |
||
2 | 959 |
" |
7 | 960 |
self testReading1 |
2 | 961 |
" |
27 | 962 |
! |
963 |
||
964 |
testSmallIntegerArithmetic |
|
965 |
"arithmetic tests. |
|
966 |
Notice, the arithmetic tests are both performed via regular sends |
|
967 |
and via constructed performs. The reason is to test both inlined |
|
968 |
JIT-compiler code AND the regular methods code." |
|
969 |
||
970 |
|s n1 n2 t| |
|
971 |
||
972 |
"/ test division and modulu ... |
|
973 |
self test:[1 printString = '1']. |
|
974 |
self test:[10 printString = '10']. |
|
975 |
self test:[100 printString = '100']. |
|
976 |
self test:[1000 printString = '1000']. |
|
977 |
self test:[10000 printString = '10000']. |
|
978 |
self test:[100000 printString = '100000']. |
|
979 |
||
32 | 980 |
n1 := 100000. |
981 |
n2 := n1 negated. |
|
982 |
||
983 |
self test:[n1 printString = '100000']. |
|
984 |
self test:[n2 printString = '-100000']. |
|
31 | 985 |
|
32 | 986 |
self test:[(n1 * 0) printString = '0']. |
987 |
self test:[(n1 perform:'*' asSymbol with:0) printString = '0']. |
|
988 |
||
989 |
self test:[(n1 * 1) printString = '100000']. |
|
990 |
self test:[(n1 perform:'*' asSymbol with:1) printString = '100000']. |
|
991 |
self test:[(n2 * 1) printString = '-100000']. |
|
992 |
self test:[(n2 perform:'*' asSymbol with:1) printString = '-100000']. |
|
31 | 993 |
|
32 | 994 |
self test:[(n1 * -1) printString = '-100000']. |
995 |
self test:[(n1 perform:'*' asSymbol with:-1) printString = '-100000']. |
|
996 |
self test:[(n2 * -1) printString = '100000']. |
|
997 |
self test:[(n2 perform:'*' asSymbol with:-1) printString = '100000']. |
|
31 | 998 |
|
32 | 999 |
self test:[(n1 * 2) printString = '200000']. |
1000 |
self test:[(n1 perform:'*' asSymbol with:2) printString = '200000']. |
|
1001 |
self test:[(n1 * 3) printString = '300000']. |
|
1002 |
self test:[(n1 perform:'*' asSymbol with:3) printString = '300000']. |
|
1003 |
self test:[(n1 * 4) printString = '400000']. |
|
1004 |
self test:[(n1 perform:'*' asSymbol with:4) printString = '400000']. |
|
1005 |
self test:[(n1 * 5) printString = '500000']. |
|
1006 |
self test:[(n1 perform:'*' asSymbol with:5) printString = '500000']. |
|
1007 |
self test:[(n1 * 6) printString = '600000']. |
|
1008 |
self test:[(n1 perform:'*' asSymbol with:6) printString = '600000']. |
|
1009 |
self test:[(n1 * 7) printString = '700000']. |
|
1010 |
self test:[(n1 perform:'*' asSymbol with:7) printString = '700000']. |
|
31 | 1011 |
|
27 | 1012 |
"addition with overflow" |
1013 |
||
1014 |
SmallInteger maxBytes == 4 ifTrue:[ |
|
1015 |
n1 := 16r3FFFFFFF. |
|
1016 |
n2 := -16r40000000. |
|
1017 |
] ifFalse:[ |
|
1018 |
n1 := 16r3FFFFFFFFFFFFFFF. |
|
1019 |
n2 := -16r4000000000000000. |
|
1020 |
]. |
|
1021 |
self test:[n1 class == SmallInteger]. |
|
1022 |
self test:[n2 class == SmallInteger]. |
|
1023 |
||
1024 |
self test:[(n1 + 1) class == LargeInteger]. |
|
1025 |
t := n1 + 1. |
|
1026 |
self test:[(t - 1) class == SmallInteger]. |
|
1027 |
||
1028 |
self test:[(n2 - 1) class == LargeInteger]. |
|
1029 |
t := n2 - 1. |
|
1030 |
self test:[(t + 1) class == SmallInteger]. |
|
1031 |
||
1032 |
self test:[(n1 negated) class == SmallInteger]. |
|
1033 |
self test:[(n2 negated) class == LargeInteger]. |
|
1034 |
self test:[(n1 perform:'negated' asSymbol) class == SmallInteger]. |
|
1035 |
self test:[(n2 perform:'negated' asSymbol) class == LargeInteger]. |
|
1036 |
||
28 | 1037 |
self test:[(n1 abs == n1)]. |
1038 |
self test:[(n2 abs = n2 negated)]. |
|
1039 |
self test:[(n1 perform:'abs' asSymbol) == n1]. |
|
1040 |
self test:[(n2 perform:'abs' asSymbol) = n2 negated]. |
|
1041 |
||
27 | 1042 |
" |
1043 |
self testSmallIntegerArithmetic |
|
1044 |
" |
|
1045 |
||
1046 |
"Created: / 6.6.1999 / 14:47:51 / cg" |
|
32 | 1047 |
"Modified: / 9.6.1999 / 17:47:56 / cg" |
2 | 1048 |
! ! |
1049 |
||
1050 |
!IntegerTest class methodsFor:'documentation'! |
|
1051 |
||
1052 |
version |
|
1053 |
^ '$Header$' |
|
1054 |
! ! |