RegressionTests__SmallIntegerTest.st
changeset 1347 e965d238a810
parent 1306 9b2ba728b70e
child 1447 2351db93aa5b
child 1499 26a16a04219b
--- a/RegressionTests__SmallIntegerTest.st	Thu Mar 10 15:44:12 2016 +0100
+++ b/RegressionTests__SmallIntegerTest.st	Thu Mar 10 15:57:20 2016 +0100
@@ -18,6 +18,132 @@
 
 !SmallIntegerTest methodsFor:'tests-arithmetic'!
 
+testBitShift
+    #( 
+        (1 1 2)
+        (1 2 4)
+        (1 3 8)
+        (1 7 16r080)
+        (1 8 16r100)
+        (1 15 16r08000)
+        (1 16 16r10000)
+        (1 17 16r20000)
+        (1 30 16r040000000)
+        (1 31 16r080000000)
+        (1 32 16r100000000)
+        (1 33 16r200000000)
+
+        (1 62 16r04000000000000000)
+        (1 63 16r08000000000000000)
+        (1 64 16r10000000000000000)
+        (1 65 16r20000000000000000)
+
+        (1 126 16r040000000000000000000000000000000)
+        (1 127 16r080000000000000000000000000000000)
+        (1 128 16r100000000000000000000000000000000)
+        (1 129 16r200000000000000000000000000000000)
+
+        (16r10 1 16r20)
+        (16r10 2 16r40)
+        (16r10 3 16r80)
+        (16r10 7 16r0800)
+        (16r10 8 16r1000)
+        (16r10 15 16r080000)
+        (16r10 16 16r100000)
+        (16r10 17 16r200000)
+        (16r10 30 16r0400000000)
+        (16r10 31 16r0800000000)
+        (16r10 32 16r1000000000)
+        (16r10 33 16r2000000000)
+
+        (16r10 62 16r040000000000000000)
+        (16r10 63 16r080000000000000000)
+        (16r10 64 16r100000000000000000)
+        (16r10 65 16r200000000000000000)
+
+        (16r10 126 16r0400000000000000000000000000000000)
+        (16r10 127 16r0800000000000000000000000000000000)
+        (16r10 128 16r1000000000000000000000000000000000)
+        (16r10 129 16r2000000000000000000000000000000000)
+    ) triplesDo:[:val :cnt :expected |
+        |rslt1 rslt2|
+        
+        rslt1 := val bitShift:cnt.
+        self assert:(rslt1 = expected).
+        expected class == SmallInteger ifTrue:[
+            self assert:(rslt1 == expected)
+        ].    
+        rslt2 := rslt1 bitShift:cnt negated.
+        self assert:(rslt2 = val).
+        val class == SmallInteger ifTrue:[
+            self assert:(rslt2 == val)
+        ].    
+    ].
+!
+
+testBitShiftNegative
+    #( 
+        (-1 1 -2)
+        (-1 2 -4)
+        (-1 3 -8)
+        (-1 7 -16r080)
+        (-1 8 -16r100)
+        (-1 15 -16r08000)
+        (-1 16 -16r10000)
+        (-1 17 -16r20000)
+        (-1 30 -16r040000000)
+        (-1 31 -16r080000000)
+        (-1 32 -16r100000000)
+        (-1 33 -16r200000000)
+
+        (-1 62 -16r04000000000000000)
+        (-1 63 -16r08000000000000000)
+        (-1 64 -16r10000000000000000)
+        (-1 65 -16r20000000000000000)
+
+        (-1 126 -16r040000000000000000000000000000000)
+        (-1 127 -16r080000000000000000000000000000000)
+        (-1 128 -16r100000000000000000000000000000000)
+        (-1 129 -16r200000000000000000000000000000000)
+
+        (-16r10 1 -16r20)
+        (-16r10 2 -16r40)
+        (-16r10 3 -16r80)
+        (-16r10 7 -16r0800)
+        (-16r10 8 -16r1000)
+        (-16r10 15 -16r080000)
+        (-16r10 16 -16r100000)
+        (-16r10 17 -16r200000)
+        (-16r10 30 -16r0400000000)
+        (-16r10 31 -16r0800000000)
+        (-16r10 32 -16r1000000000)
+        (-16r10 33 -16r2000000000)
+
+        (-16r10 62 -16r040000000000000000)
+        (-16r10 63 -16r080000000000000000)
+        (-16r10 64 -16r100000000000000000)
+        (-16r10 65 -16r200000000000000000)
+
+        (-16r10 126 -16r0400000000000000000000000000000000)
+        (-16r10 127 -16r0800000000000000000000000000000000)
+        (-16r10 128 -16r1000000000000000000000000000000000)
+        (-16r10 129 -16r2000000000000000000000000000000000)
+    ) triplesDo:[:val :cnt :expected |
+        |rslt1 rslt2|
+        
+        rslt1 := val bitShift:cnt.
+        self assert:(rslt1 = expected).
+        expected class == SmallInteger ifTrue:[
+            self assert:(rslt1 == expected)
+        ].    
+        rslt2 := rslt1 bitShift:cnt negated.
+        self assert:(rslt2 = val).
+        val class == SmallInteger ifTrue:[
+            self assert:(rslt2 == val)
+        ].    
+    ].
+!
+
 testDivide
         |zero _1 _2 _3 _4 _m2 _m4|
 
@@ -161,6 +287,16 @@
     ]
 !
 
+testMaxValPointerSizeConsistency
+    SmallInteger maxBytes == 4 ifTrue:[
+        self assert: ((SmallInteger maxBits == 31) or:[SmallInteger maxBits == 32]).
+        self assert: (ExternalAddress pointerSize == 4).
+    ] ifFalse:[
+        self assert: ((SmallInteger maxBits == 63) or:[SmallInteger maxBits == 64]).
+        self assert: (ExternalAddress pointerSize == 8).
+    ]
+!
+
 testMinVal
     "/ the original code did not check for pointer-size;