#REFACTORING
class: RegressionTests::UninterpretedBytesTest
changed: #test01_int16Access
--- a/RegressionTests__UninterpretedBytesTest.st Mon Mar 14 17:12:57 2016 +0100
+++ b/RegressionTests__UninterpretedBytesTest.st Tue Mar 15 22:49:23 2016 +0100
@@ -71,69 +71,85 @@
!
test01_int16Access
- |bytes|
+ |check|
- bytes := #[ 16r10 16r20 16r30 16r40 ].
+ check :=
+ [:bytes1 :bytes2 |
+ |wBytes|
- 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.
+ "/ bytes1 := #[ 16r10 16r20 16r30 16r40 ].
+ self assert:(bytes1 unsignedInt16At:1 MSB:true) = 16r1020.
+ self assert:(bytes1 unsignedInt16At:1 MSB:false) = 16r2010.
+ self assert:(bytes1 unsignedInt16At:2 MSB:true) = 16r2030.
+ self assert:(bytes1 unsignedInt16At:2 MSB:false) = 16r3020.
+ self assert:(bytes1 unsignedInt16At:3 MSB:true) = 16r3040.
+ self assert:(bytes1 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.
+ self assert:(bytes1 signedInt16At:1 MSB:true) = 16r1020.
+ self assert:(bytes1 signedInt16At:1 MSB:false) = 16r2010.
+ self assert:(bytes1 signedInt16At:2 MSB:true) = 16r2030.
+ self assert:(bytes1 signedInt16At:2 MSB:false) = 16r3020.
+ self assert:(bytes1 signedInt16At:3 MSB:true) = 16r3040.
+ self assert:(bytes1 signedInt16At:3 MSB:false) = 16r4030.
- bytes := #[ 16rFF 16r7F 16r80 16r81 ].
+ "/ bytes2 := #[ 16rFF 16r7F 16r80 16r81 ].
+ self assert:(bytes2 unsignedInt16At:1 MSB:true) = 16rFF7F.
+ self assert:(bytes2 unsignedInt16At:1 MSB:false) = 16r7FFF.
+ self assert:(bytes2 unsignedInt16At:2 MSB:true) = 16r7F80.
+ self assert:(bytes2 unsignedInt16At:2 MSB:false) = 16r807F.
+ self assert:(bytes2 unsignedInt16At:3 MSB:true) = 16r8081.
+ self assert:(bytes2 unsignedInt16At:3 MSB:false) = 16r8180.
- 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:(bytes2 signedInt16At:1 MSB:true) = -129. "/ 16rFF7F signExtendedShortValue
+ self assert:(bytes2 signedInt16At:1 MSB:false) = 16r7FFF.
+ self assert:(bytes2 signedInt16At:2 MSB:true) = 16r7F80.
+ self assert:(bytes2 signedInt16At:2 MSB:false) = -32641. "/ 16r807F signExtendedShortValue.
+ self assert:(bytes2 signedInt16At:3 MSB:true) = -32639. "/ 16r8081 signExtendedShortValue.
+ self assert:(bytes2 signedInt16At:3 MSB:false) = -32384. "/ 16r8180 signExtendedShortValue.
+
+ wBytes := bytes2 copy.
- 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.
+ wBytes unsignedInt16At:1 put:16r1020 MSB:false.
+ self assert:(wBytes unsignedInt16At:1 MSB:false) = 16r1020.
+ self assert:(wBytes signedInt16At:1 MSB:false) = 16r1020.
+
+ wBytes unsignedInt16At:1 put:16r1020 MSB:true.
+ self assert:(wBytes unsignedInt16At:1 MSB:false) = 16r2010.
+ self assert:(wBytes signedInt16At:1 MSB:false) = 16r2010.
- bytes := bytes copy.
+ wBytes unsignedInt16At:1 put:16rFFFE MSB:false.
+ self assert:(wBytes unsignedInt16At:1 MSB:false) = 16rFFFE.
+ self assert:(wBytes signedInt16At:1 MSB:false) = -2.
- bytes unsignedInt16At:1 put:16r1020 MSB:false.
- self assert:(bytes unsignedInt16At:1 MSB:false) = 16r1020.
- self assert:(bytes signedInt16At:1 MSB:false) = 16r1020.
+ wBytes unsignedInt16At:1 put:16rFFFE MSB:true.
+ self assert:(wBytes unsignedInt16At:1 MSB:false) = 16rFEFF.
+ self assert:(wBytes signedInt16At:1 MSB:false) = -257. "/ 16rFEFF signExtendedShortValue
- bytes unsignedInt16At:1 put:16r1020 MSB:true.
- self assert:(bytes unsignedInt16At:1 MSB:false) = 16r2010.
- self assert:(bytes signedInt16At:1 MSB:false) = 16r2010.
+ wBytes signedInt16At:1 put:16r1020 MSB:false.
+ self assert:(wBytes unsignedInt16At:1 MSB:false) = 16r1020.
+ self assert:(wBytes signedInt16At:1 MSB:false) = 16r1020.
- bytes unsignedInt16At:1 put:16rFFFE MSB:false.
- self assert:(bytes unsignedInt16At:1 MSB:false) = 16rFFFE.
- self assert:(bytes signedInt16At:1 MSB:false) = -2.
+ wBytes signedInt16At:1 put:16r1020 MSB:true.
+ self assert:(wBytes unsignedInt16At:1 MSB:false) = 16r2010.
+ self assert:(wBytes signedInt16At:1 MSB:false) = 16r2010.
- 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
+ wBytes signedInt16At:1 put:-3 MSB:false.
+ self assert:(wBytes unsignedInt16At:1 MSB:false) = 16rFFFD.
+ self assert:(wBytes signedInt16At:1 MSB:false) = -3.
+ ].
- bytes signedInt16At:1 put:16r1020 MSB:false.
- self assert:(bytes unsignedInt16At:1 MSB:false) = 16r1020.
- self assert:(bytes signedInt16At:1 MSB:false) = 16r1020.
+ check
+ value: #[ 16r10 16r20 16r30 16r40 ]
+ value: #[ 16rFF 16r7F 16r80 16r81 ].
- bytes signedInt16At:1 put:16r1020 MSB:true.
- self assert:(bytes unsignedInt16At:1 MSB:false) = 16r2010.
- self assert:(bytes signedInt16At:1 MSB:false) = 16r2010.
+ check
+ value: (WordArray with:16r2010 with:16r4030)
+ value: (WordArray with:16r7FFF with:16r8180).
- bytes signedInt16At:1 put:-3 MSB:false.
- self assert:(bytes unsignedInt16At:1 MSB:false) = 16rFFFD.
- self assert:(bytes signedInt16At:1 MSB:false) = -3.
+ check
+ value: (IntegerArray with:16r40302010)
+ value: (IntegerArray with:16r81807FFF).
+
"
self run:#test01_int16Access
@@ -289,6 +305,35 @@
"
self run:#test90_backwardCompatibility
"
+!
+
+testFloatAccess
+ |bytes|
+
+ bytes := ByteArray new:4.
+ bytes floatAt:1 put:1.234.
+ self assert:(bytes = #[182 243 157 63]).
+
+ bytes floatAt:1 put:2.345 asShortFloat.
+ self assert:(bytes = #[123 20 22 64]).
+
+ bytes floatAt:1 put:345.
+ self assert:(bytes = #[0 128 172 67]).
+
+
+ bytes := ByteArray new:8.
+ bytes doubleAt:1 put:1.234.
+ self assert:(bytes = #[88 57 180 200 118 190 243 63]).
+
+ bytes doubleAt:1 put:2.345 asShortFloat.
+ self assert:(bytes = #[0 0 0 96 143 194 2 64]).
+
+ bytes doubleAt:1 put:345.
+ self assert:(bytes = #[0 0 0 0 0 144 117 64]).
+
+ "
+ self run:#testFloatAccess
+ "
! !
!UninterpretedBytesTest class methodsFor:'documentation'!