RegressionTests__SmallIntegerTest.st
author Claus Gittinger <cg@exept.de>
Tue, 07 Apr 2009 16:11:00 +0200
changeset 364 fd3ff5ad69f5
parent 310 f7a1f000a281
child 619 f918fa22ad81
permissions -rw-r--r--
*** empty log message ***

"{ Package: 'exept:regression' }"

"{ NameSpace: RegressionTests }"

TestCase subclass:#SmallIntegerTest
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'tests-Regression'
!


!SmallIntegerTest methodsFor:'tests-arithmetic'!

testDivide
        self assert: 2 / 1 = 2.
        self assert: (3 / 2) isFraction.
        self assert: 4 / 2 = 2.
        self should: [ 1 / 0 ] raise: ZeroDivide.
!

testMultiply
    |i ii|

    #( 
        16r3fff
        16r7fff 
        16rffff 
        16r3fffffff
        16r7fffffff
        16rffffffff
        16r20000000
        16r40000000
        16r80000000
        16r100000000
        16r20000001
        16r40000001
        16r80000001
        16r100000001
    ) 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
    ) 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$'
! !