#FEATURE
authorClaus Gittinger <cg@exept.de>
Sun, 13 Mar 2016 01:57:44 +0100
changeset 1357 6d1158181ddc
parent 1356 a8e8d673f22e
child 1358 27c28838cdb5
#FEATURE class: RegressionTests::UninterpretedBytesTest added:5 methods
RegressionTests__UninterpretedBytesTest.st
--- a/RegressionTests__UninterpretedBytesTest.st	Fri Mar 11 18:09:41 2016 +0100
+++ b/RegressionTests__UninterpretedBytesTest.st	Sun Mar 13 01:57:44 2016 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "{ Package: 'exept:regression' }"
 
 "{ NameSpace: RegressionTests }"
@@ -12,7 +14,228 @@
 
 !UninterpretedBytesTest methodsFor:'tests'!
 
-testFloatAccess
+test00_byteAccess
+    |bytes|
+
+    bytes := #[ 16r10 16r20 16r30 16r40 ].
+
+    self assert:(bytes byteAt:1) == 16r10.
+    self assert:(bytes byteAt:2) == 16r20.
+    self assert:(bytes byteAt:3) == 16r30.
+    self assert:(bytes byteAt:4) == 16r40.
+
+    self assert:(bytes signedByteAt:1) == 16r10.
+    self assert:(bytes signedByteAt:2) == 16r20.
+    self assert:(bytes signedByteAt:3) == 16r30.
+    self assert:(bytes signedByteAt:4) == 16r40.
+
+    bytes := #[ 16rFF 16r7F 16r80 16r81 ].
+
+    self assert:(bytes byteAt:1) == 16rFF.
+    self assert:(bytes byteAt:2) == 16r7F.
+    self assert:(bytes byteAt:3) == 16r80.
+    self assert:(bytes byteAt:4) == 16r81.
+
+    self assert:(bytes signedByteAt:1) == -1.
+    self assert:(bytes signedByteAt:2) == 127.
+    self assert:(bytes signedByteAt:3) == -128.
+    self assert:(bytes signedByteAt:4) == -127.
+
+    bytes := bytes copy.
+
+    bytes byteAt:1 put:16r10.
+    self assert:(bytes byteAt:1) == 16r10.
+    self assert:(bytes signedByteAt:1) == 16r10.
+
+    bytes byteAt:1 put:16r80.
+    self assert:(bytes byteAt:1) == 16r80.
+    self assert:(bytes signedByteAt:1) == -128.
+
+    bytes signedByteAt:1 put:16r10.
+    self assert:(bytes byteAt:1) == 16r10.
+    self assert:(bytes signedByteAt:1) == 16r10.
+
+    bytes signedByteAt:1 put:-1.
+    self assert:(bytes byteAt:1) == 16rFF.
+    self assert:(bytes signedByteAt:1) == -1.
+
+    "
+     self run:#test00_byteAccess
+    "
+!
+
+test01_int16Access
+    |bytes|
+
+    bytes := #[ 16r10 16r20 16r30 16r40 ].
+
+    self assert:(bytes unsignedInt16At:1 MSB:true)  = 16r1020.
+    self assert:(bytes unsignedInt16At:1 MSB:false) = 16r2010.
+    self assert:(bytes unsignedInt16At:2 MSB:true)  = 16r2030.
+    self assert:(bytes unsignedInt16At:2 MSB:false) = 16r3020.
+    self assert:(bytes unsignedInt16At:3 MSB:true)  = 16r3040.
+    self assert:(bytes unsignedInt16At:3 MSB:false) = 16r4030.
+
+    self assert:(bytes signedInt16At:1 MSB:true)  = 16r1020.
+    self assert:(bytes signedInt16At:1 MSB:false) = 16r2010.
+    self assert:(bytes signedInt16At:2 MSB:true)  = 16r2030.
+    self assert:(bytes signedInt16At:2 MSB:false) = 16r3020.
+    self assert:(bytes signedInt16At:3 MSB:true)  = 16r3040.
+    self assert:(bytes signedInt16At:3 MSB:false) = 16r4030.
+
+
+    bytes := #[ 16rFF 16r7F 16r80 16r81 ].
+
+    self assert:(bytes unsignedInt16At:1 MSB:true)  = 16rFF7F.
+    self assert:(bytes unsignedInt16At:1 MSB:false) = 16r7FFF.
+    self assert:(bytes unsignedInt16At:2 MSB:true)  = 16r7F80.
+    self assert:(bytes unsignedInt16At:2 MSB:false) = 16r807F.
+    self assert:(bytes unsignedInt16At:3 MSB:true)  = 16r8081.
+    self assert:(bytes unsignedInt16At:3 MSB:false) = 16r8180.
+
+    self assert:(bytes signedInt16At:1 MSB:true)  = -129.  "/ 16rFF7F signExtendedShortValue
+    self assert:(bytes signedInt16At:1 MSB:false) = 16r7FFF.
+    self assert:(bytes signedInt16At:2 MSB:true)  = 16r7F80.
+    self assert:(bytes signedInt16At:2 MSB:false) = -32641. "/ 16r807F signExtendedShortValue.
+    self assert:(bytes signedInt16At:3 MSB:true)  = -32639. "/ 16r8081 signExtendedShortValue.
+    self assert:(bytes signedInt16At:3 MSB:false) = -32384. "/ 16r8180 signExtendedShortValue.
+
+    bytes := bytes copy.
+
+    bytes unsignedInt16At:1 put:16r1020 MSB:false.
+    self assert:(bytes unsignedInt16At:1 MSB:false) = 16r1020.
+    self assert:(bytes signedInt16At:1 MSB:false) = 16r1020.
+
+    bytes unsignedInt16At:1 put:16r1020 MSB:true.
+    self assert:(bytes unsignedInt16At:1 MSB:false) = 16r2010.
+    self assert:(bytes signedInt16At:1 MSB:false) = 16r2010.
+
+    bytes unsignedInt16At:1 put:16rFFFE MSB:false.
+    self assert:(bytes unsignedInt16At:1 MSB:false) = 16rFFFE.
+    self assert:(bytes signedInt16At:1 MSB:false) = -2.
+
+    bytes unsignedInt16At:1 put:16rFFFE MSB:true.
+    self assert:(bytes unsignedInt16At:1 MSB:false) = 16rFEFF.
+    self assert:(bytes signedInt16At:1 MSB:false) = -257.  "/ 16rFEFF signExtendedShortValue
+
+    bytes signedInt16At:1 put:16r1020 MSB:false.
+    self assert:(bytes unsignedInt16At:1 MSB:false) = 16r1020.
+    self assert:(bytes signedInt16At:1 MSB:false) = 16r1020.
+
+    bytes signedInt16At:1 put:16r1020 MSB:true.
+    self assert:(bytes unsignedInt16At:1 MSB:false) = 16r2010.
+    self assert:(bytes signedInt16At:1 MSB:false) = 16r2010.
+
+    bytes signedInt16At:1 put:-3 MSB:false.
+    self assert:(bytes unsignedInt16At:1 MSB:false) = 16rFFFD.
+    self assert:(bytes signedInt16At:1 MSB:false) = -3.
+
+    "
+     self run:#test01_int16Access
+    "
+!
+
+test02_int32Access
+    |bytes|
+
+    bytes := #[ 16r10 16r20 16r30 16r40 16r50 ].
+
+    self assert:(bytes unsignedInt32At:1 MSB:true)  = 16r10203040.
+    self assert:(bytes unsignedInt32At:1 MSB:false) = 16r40302010.
+    self assert:(bytes unsignedInt32At:2 MSB:true)  = 16r20304050.
+    self assert:(bytes unsignedInt32At:2 MSB:false) = 16r50403020.
+
+    self assert:(bytes signedInt32At:1 MSB:true)  = 16r10203040.
+    self assert:(bytes signedInt32At:1 MSB:false) = 16r40302010.
+    self assert:(bytes signedInt32At:2 MSB:true)  = 16r20304050.
+    self assert:(bytes signedInt32At:2 MSB:false) = 16r50403020.
+
+
+    bytes := #[ 16r80 16rFF 16r01 16r03 16r80 ].
+
+    self assert:(bytes unsignedInt32At:1 MSB:true)  = 16r80FF0103.
+    self assert:(bytes unsignedInt32At:1 MSB:false) = 16r0301FF80.
+    self assert:(bytes unsignedInt32At:2 MSB:true)  = 16rFF010380.
+    self assert:(bytes unsignedInt32At:2 MSB:false) = 16r800301FF.
+
+    self assert:(bytes signedInt32At:1 MSB:true)  = -2130771709.  "/ 16r80FF0103 signExtendedLongValue
+    self assert:(bytes signedInt32At:1 MSB:false) = 16r0301FF80.
+    self assert:(bytes signedInt32At:2 MSB:true)  = -16710784. "/ 16rFF010380 signExtendedLongValue.
+    self assert:(bytes signedInt32At:2 MSB:false) = -2147286529. "/ 16r800301FF signExtendedLongValue.
+
+    bytes := bytes copy.
+
+    bytes unsignedInt32At:1 put:16r10203040 MSB:false.
+    self assert:(bytes unsignedInt32At:1 MSB:false) = 16r10203040.
+    self assert:(bytes signedInt32At:1 MSB:false) = 16r10203040.
+
+    bytes unsignedInt32At:1 put:16r10203040 MSB:true.
+    self assert:(bytes unsignedInt32At:1 MSB:false) = 16r40302010.
+    self assert:(bytes signedInt32At:1 MSB:false) = 16r40302010.
+
+    bytes unsignedInt32At:1 put:16r10203080 MSB:true.
+    self assert:(bytes unsignedInt32At:1 MSB:false) = 16r80302010.
+    self assert:(bytes signedInt32At:1 MSB:false) = -2144329712. "/ 16r80302010 signExtendedLongValue.
+
+    bytes unsignedInt32At:1 put:16rFFFFFFFE MSB:false.
+    self assert:(bytes unsignedInt32At:1 MSB:false) = 16rFFFFFFFE.
+    self assert:(bytes signedInt32At:1 MSB:false) = -2.
+
+    bytes signedInt32At:1 put:16r40302010 MSB:false.
+    self assert:(bytes unsignedInt32At:1 MSB:false) = 16r40302010.
+    self assert:(bytes signedInt32At:1 MSB:false) = 16r40302010.
+
+    bytes signedInt32At:1 put:-3 MSB:false.
+    self assert:(bytes unsignedInt32At:1 MSB:false) = 16rFFFFFFFD.
+    self assert:(bytes signedInt32At:1 MSB:false) = -3.
+
+    "
+     self run:#test02_int32Access
+    "
+!
+
+test03_int64Access
+    |bytes|
+
+    bytes := #[ 16r10 16r20 16r30 16r40 16r50 16r60 16r70 16r80 16r90].
+
+    self assert:(bytes unsignedInt64At:1 MSB:true)  = 16r1020304050607080.
+    self assert:(bytes unsignedInt64At:1 MSB:false) = 16r8070605040302010.
+    self assert:(bytes unsignedInt64At:2 MSB:true)  = 16r2030405060708090.
+    self assert:(bytes unsignedInt64At:2 MSB:false) = 16r9080706050403020.
+
+    self assert:(bytes signedInt64At:1 MSB:true)  = 16r1020304050607080.
+    self assert:(bytes signedInt64At:1 MSB:false) = -9191740941672636400. "/ 16r8070605040302010  signExtendedLongLongValue
+    self assert:(bytes signedInt64At:2 MSB:true)  = 16r2030405060708090.
+    self assert:(bytes signedInt64At:2 MSB:false) = -8034298176263409632. "/ 16r9080706050403020 signExtendedLongLongValue.
+
+    bytes := bytes copy.
+    bytes unsignedInt64At:1 put:16r30405060708090A0 MSB:true.
+    self assert:(bytes unsignedInt64At:1 MSB:true)   = 16r30405060708090A0.
+    self assert:(bytes unsignedInt64At:1 MSB:false)  = 16rA090807060504030.
+    self assert:(bytes signedInt64At:1 MSB:true)   = 16r30405060708090A0.
+    self assert:(bytes signedInt64At:1 MSB:false)  = -6876855410854182864. "/ 16rA090807060504030 signExtendedLongLongValue.
+
+    bytes signedInt64At:1 put:-6876855410854182864 MSB:true.
+    self assert:(bytes unsignedInt64At:1 MSB:true)   = 16rA090807060504030.
+    self assert:(bytes signedInt64At:1 MSB:true)   = -6876855410854182864.
+
+    bytes signedInt64At:1 put:-6876855410854182864 MSB:false.
+    self assert:(bytes unsignedInt64At:1 MSB:false)   = 16rA090807060504030.
+    self assert:(bytes signedInt64At:1 MSB:false)   = -6876855410854182864.
+
+    bytes unsignedInt64At:1 put:16r30405060708090A0 MSB:false.
+    self assert:(bytes unsignedInt64At:1 MSB:true)   = 16rA090807060504030.
+    self assert:(bytes unsignedInt64At:1 MSB:false)  = 16r30405060708090A0.
+    self assert:(bytes signedInt64At:1 MSB:true)  = -6876855410854182864. "/ 16rA090807060504030 signExtendedLongLongValue.
+    self assert:(bytes signedInt64At:1 MSB:false)   = 16r30405060708090A0.
+
+    "
+     self run:#test03_int64Access
+    "
+!
+
+test10_floatAccess
     |bytes|
 
     bytes := ByteArray new:4.
@@ -37,7 +260,7 @@
     self assert:(bytes = #[0 0 0 0 0 144 117 64]).
 
     "
-     self run:#testFloatAccess
+     self run:#test10_floatAccess
     "
 ! !