author | Stefan Vogel <sv@exept.de> |
Tue, 09 Aug 2011 10:53:00 +0200 | |
changeset 619 | f918fa22ad81 |
parent 364 | fd3ff5ad69f5 |
child 1074 | 905aea054cf4 |
permissions | -rw-r--r-- |
310 | 1 |
"{ Package: 'exept:regression' }" |
2 |
||
3 |
"{ NameSpace: RegressionTests }" |
|
4 |
||
5 |
TestCase subclass:#SmallIntegerTest |
|
6 |
instanceVariableNames:'' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
9 |
category:'tests-Regression' |
|
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 |
||
21 |
testDivide |
|
619
f918fa22ad81
Circumvent compiler error about div by zero
Stefan Vogel <sv@exept.de>
parents:
364
diff
changeset
|
22 |
|zero| |
f918fa22ad81
Circumvent compiler error about div by zero
Stefan Vogel <sv@exept.de>
parents:
364
diff
changeset
|
23 |
|
f918fa22ad81
Circumvent compiler error about div by zero
Stefan Vogel <sv@exept.de>
parents:
364
diff
changeset
|
24 |
"circumvent compiler error about division by zero" |
f918fa22ad81
Circumvent compiler error about div by zero
Stefan Vogel <sv@exept.de>
parents:
364
diff
changeset
|
25 |
zero := 0. |
f918fa22ad81
Circumvent compiler error about div by zero
Stefan Vogel <sv@exept.de>
parents:
364
diff
changeset
|
26 |
|
310 | 27 |
self assert: 2 / 1 = 2. |
28 |
self assert: (3 / 2) isFraction. |
|
29 |
self assert: 4 / 2 = 2. |
|
619
f918fa22ad81
Circumvent compiler error about div by zero
Stefan Vogel <sv@exept.de>
parents:
364
diff
changeset
|
30 |
self should: [ 1 / zero ] raise: ZeroDivide. |
364 | 31 |
! |
32 |
||
33 |
testMultiply |
|
34 |
|i ii| |
|
35 |
||
36 |
#( |
|
37 |
16r3fff |
|
38 |
16r7fff |
|
39 |
16rffff |
|
40 |
16r3fffffff |
|
41 |
16r7fffffff |
|
42 |
16rffffffff |
|
43 |
16r20000000 |
|
44 |
16r40000000 |
|
45 |
16r80000000 |
|
46 |
16r100000000 |
|
47 |
16r20000001 |
|
48 |
16r40000001 |
|
49 |
16r80000001 |
|
50 |
16r100000001 |
|
51 |
) do:[:x | |
|
52 |
i := x. |
|
53 |
ii := i * i. |
|
54 |
self assert:((ii / i) = i). |
|
55 |
i class == SmallInteger ifTrue:[ |
|
56 |
self assert:((ii / i) == i). |
|
57 |
]. |
|
58 |
||
59 |
i := x negated. |
|
60 |
ii := i * i. |
|
61 |
self assert:((ii / i) = i). |
|
62 |
i class == SmallInteger ifTrue:[ |
|
63 |
self assert:((ii / i) == i). |
|
64 |
]. |
|
65 |
]. |
|
66 |
! |
|
67 |
||
68 |
testNegation |
|
69 |
|i iN iNN| |
|
70 |
||
71 |
#( |
|
72 |
16r3fffffff |
|
73 |
16r7fffffff |
|
74 |
16rffffffff |
|
75 |
16r20000000 |
|
76 |
16r40000000 |
|
77 |
16r80000000 |
|
78 |
16r100000000 |
|
79 |
16r20000001 |
|
80 |
16r40000001 |
|
81 |
16r80000001 |
|
82 |
16r100000001 |
|
83 |
) do:[:x | |
|
84 |
i := x. |
|
85 |
iN := i negated. |
|
86 |
iNN := iN negated. |
|
87 |
self assert:(i = iNN). |
|
88 |
i class == SmallInteger ifTrue:[ |
|
89 |
self assert:(i == iNN). |
|
90 |
]. |
|
91 |
]. |
|
310 | 92 |
! ! |
93 |
||
94 |
!SmallIntegerTest methodsFor:'tests-class protocol'! |
|
95 |
||
96 |
testBasicNew |
|
97 |
self should: [SmallInteger basicNew] raise: TestResult error. |
|
98 |
! |
|
99 |
||
100 |
testMaxVal |
|
101 |
"/ the original code did not check for pointer-size; |
|
102 |
||
103 |
Smalltalk isSmalltalkX ifTrue:[ |
|
104 |
SmallInteger maxBytes == 4 ifTrue:[ |
|
105 |
self should: [SmallInteger maxVal = 16r3FFFFFFF]. |
|
106 |
self should: [SmallInteger maxVal == 16r3FFFFFFF]. |
|
107 |
] ifFalse:[ |
|
108 |
self should: [SmallInteger maxVal = 16r3FFFFFFFFFFFFFFF]. |
|
109 |
self should: [SmallInteger maxVal == 16r3FFFFFFFFFFFFFFF]. |
|
110 |
]. |
|
111 |
] ifFalse:[ |
|
112 |
self should: [SmallInteger maxVal = 16r3FFFFFFF]. |
|
113 |
] |
|
114 |
! |
|
115 |
||
116 |
testMinVal |
|
117 |
"/ the original code did not check for pointer-size; |
|
118 |
||
119 |
Smalltalk isSmalltalkX ifTrue:[ |
|
120 |
SmallInteger maxBytes == 4 ifTrue:[ |
|
121 |
self should: [SmallInteger minVal = -16r40000000]. |
|
122 |
self should: [SmallInteger minVal == -16r40000000]. |
|
123 |
] ifFalse:[ |
|
124 |
self should: [SmallInteger minVal = -16r4000000000000000]. |
|
125 |
self should: [SmallInteger minVal == -16r4000000000000000]. |
|
126 |
]. |
|
127 |
] ifFalse:[ |
|
128 |
self should: [SmallInteger minVal = -16r40000000]. |
|
129 |
] |
|
130 |
! |
|
131 |
||
132 |
testNew |
|
133 |
self should: [SmallInteger new] raise: TestResult error. |
|
134 |
! ! |
|
135 |
||
136 |
!SmallIntegerTest class methodsFor:'documentation'! |
|
137 |
||
138 |
version |
|
139 |
^ '$Header$' |
|
140 |
! ! |