class: RegressionTests::SmallIntegerTest
changed:
#testDivide
#testMultiply
#testNegation
"{ Package: 'exept:regression' }"
"{ NameSpace: RegressionTests }"
TestCase subclass:#SmallIntegerTest
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'tests-Regression-Numbers'
!
!SmallIntegerTest class methodsFor:'others'!
version_CVS
^ '$Header$'
! !
!SmallIntegerTest methodsFor:'tests-arithmetic'!
testDivide
|zero _1 _2 _3 _4 _m2 _m4|
"circumvent compiler error about division by zero"
zero := 0.
self assert: 2 / 1 = 2.
self assert: (3 / 2) isFraction.
self assert: 4 / 2 = 2.
self assert: 4 / -2 = -2.
self assert: -4 / 2 = -2.
self assert: -4 / -2 = 2.
self should: [ 1 / zero ] raise: ZeroDivide.
_1 := 1.
_2 := 2.
_3 := 3.
_4 := 4.
_m2 := -2.
_m4 := -4.
self assert: _2 / _1 = _2.
self assert: (_3 / _2) isFraction.
self assert: _4 / _2 = 2.
self assert: _4 / _m2 = -2.
self assert: _m4 / _2 = -2.
self assert: _m4 / _m2 = 2.
!
testMultiply
|i ii|
#(
16r3fff
16r7fff
16rffff
16r3fffffff
16r7fffffff
16rffffffff
16r20000000
16r40000000
16r80000000
16r100000000
16r20000001
16r40000001
16r80000001
16r100000001
"/ for 64 bit machines:
16r3fffffffffffffff
16r7fffffffffffffff
16rffffffffffffffff
16r2000000000000000
16r4000000000000000
16r8000000000000000
16r10000000000000000
16r2000000000000001
16r4000000000000001
16r8000000000000001
16r10000000000000001
) do:[:x |
i := x.
ii := i * i.
self assert:((ii / i) = i).
i class == SmallInteger ifTrue:[
self assert:((ii / i) == i).
].
i := x negated.
ii := i * i.
self assert:((ii / i) = i).
i class == SmallInteger ifTrue:[
self assert:((ii / i) == i).
].
].
!
testNegation
|i iN iNN|
#(
16r3fffffff
16r7fffffff
16rffffffff
16r20000000
16r40000000
16r80000000
16r100000000
16r20000001
16r40000001
16r80000001
16r100000001
"/ for 64bit machines:
16r3fffffffffffffff
16r7fffffffffffffff
16rffffffffffffffff
16r2000000000000000
16r4000000000000000
16r8000000000000000
16r10000000000000000
16r2000000000000001
16r4000000000000001
16r8000000000000001
16r10000000000000001
) do:[:x |
i := x.
iN := i negated.
iNN := iN negated.
self assert:(i = iNN).
i class == SmallInteger ifTrue:[
self assert:(i == iNN).
].
].
! !
!SmallIntegerTest methodsFor:'tests-class protocol'!
testBasicNew
self should: [SmallInteger basicNew] raise: TestResult error.
!
testMaxVal
"/ the original code did not check for pointer-size;
Smalltalk isSmalltalkX ifTrue:[
SmallInteger maxBytes == 4 ifTrue:[
self should: [SmallInteger maxVal = 16r3FFFFFFF].
self should: [SmallInteger maxVal == 16r3FFFFFFF].
] ifFalse:[
self should: [SmallInteger maxVal = 16r3FFFFFFFFFFFFFFF].
self should: [SmallInteger maxVal == 16r3FFFFFFFFFFFFFFF].
].
] ifFalse:[
self should: [SmallInteger maxVal = 16r3FFFFFFF].
]
!
testMinVal
"/ the original code did not check for pointer-size;
Smalltalk isSmalltalkX ifTrue:[
SmallInteger maxBytes == 4 ifTrue:[
self should: [SmallInteger minVal = -16r40000000].
self should: [SmallInteger minVal == -16r40000000].
] ifFalse:[
self should: [SmallInteger minVal = -16r4000000000000000].
self should: [SmallInteger minVal == -16r4000000000000000].
].
] ifFalse:[
self should: [SmallInteger minVal = -16r40000000].
]
!
testNew
self should: [SmallInteger new] raise: TestResult error.
! !
!SmallIntegerTest class methodsFor:'documentation'!
version
^ '$Header$'
! !