65 self assert:(bytes byteAt:1) == 16rFF. |
65 self assert:(bytes byteAt:1) == 16rFF. |
66 self assert:(bytes signedByteAt:1) == -1. |
66 self assert:(bytes signedByteAt:1) == -1. |
67 |
67 |
68 "/ check immutablility checks |
68 "/ check immutablility checks |
69 bytes := #[ 16rFF 16r00 ] beImmutable. |
69 bytes := #[ 16rFF 16r00 ] beImmutable. |
70 self |
70 self |
71 should:[ |
71 should:[ |
72 bytes byteAt:1 put:0 |
72 bytes byteAt:1 put:0 |
73 ] |
73 ] |
74 raise:NoModificationError. |
74 raise:NoModificationError. |
75 self assert:(bytes at:1) == 16rFF. |
75 self assert:(bytes at:1) == 16rFF. |
76 |
76 |
77 "/ check bounds checks |
77 "/ check bounds checks |
78 #(3 0 -1 -2) do:[:badIndex | |
78 #(3 0 -1 -2) do:[:badIndex | |
79 self |
79 self |
80 should:[ |
80 should:[ |
81 #[ 16rFF 16r00 ] byteAt:badIndex |
81 #[ 16rFF 16r00 ] byteAt:badIndex |
82 ] |
82 ] |
83 raise:SubscriptOutOfBoundsError. |
83 raise:SubscriptOutOfBoundsError. |
84 |
84 |
85 self |
85 self |
86 should:[ |
86 should:[ |
87 #[ 16rFF 16r00 ] signedByteAt:badIndex |
87 #[ 16rFF 16r00 ] signedByteAt:badIndex |
88 ] |
88 ] |
89 raise:SubscriptOutOfBoundsError. |
89 raise:SubscriptOutOfBoundsError. |
90 |
90 |
91 self |
91 self |
92 should:[ |
92 should:[ |
93 #[ 16rFF 16r00 ] byteAt:badIndex put:0 |
93 #[ 16rFF 16r00 ] byteAt:badIndex put:0 |
94 ] |
94 ] |
95 raise:SubscriptOutOfBoundsError. |
95 raise:SubscriptOutOfBoundsError. |
96 |
96 |
97 self |
97 self |
98 should:[ |
98 should:[ |
99 #[ 16rFF 16r00 ] signedByteAt:badIndex put:0 |
99 #[ 16rFF 16r00 ] signedByteAt:badIndex put:0 |
100 ] |
100 ] |
101 raise:SubscriptOutOfBoundsError. |
101 raise:SubscriptOutOfBoundsError. |
102 ] |
102 ] |
103 |
103 |
104 " |
104 " |
105 self run:#test00_byteAccess |
105 self run:#test00_byteAccess |
106 " |
106 " |
107 ! |
107 ! |
108 |
108 |
109 test01_int16Access |
109 test01_int16Access |
110 |check bytes| |
110 |check bytes| |
111 |
111 |
112 check := |
112 check := |
113 [:bytes1 :bytes2 | |
113 [:bytes1 :bytes2 | |
114 |wBytes| |
114 |wBytes| |
115 |
115 |
116 "/ bytes1 := #[ 16r10 16r20 16r30 16r40 ]. |
116 "/ bytes1 := #[ 16r10 16r20 16r30 16r40 ]. |
117 self assert:(bytes1 unsignedInt16At:1 MSB:true) = 16r1020. |
117 self assert:(bytes1 unsignedInt16At:1 MSB:true) = 16r1020. |
118 self assert:(bytes1 unsignedInt16At:1 MSB:false) = 16r2010. |
118 self assert:(bytes1 unsignedInt16At:1 MSB:false) = 16r2010. |
119 self assert:(bytes1 unsignedInt16At:2 MSB:true) = 16r2030. |
119 self assert:(bytes1 unsignedInt16At:2 MSB:true) = 16r2030. |
120 self assert:(bytes1 unsignedInt16At:2 MSB:false) = 16r3020. |
120 self assert:(bytes1 unsignedInt16At:2 MSB:false) = 16r3020. |
121 self assert:(bytes1 unsignedInt16At:3 MSB:true) = 16r3040. |
121 self assert:(bytes1 unsignedInt16At:3 MSB:true) = 16r3040. |
122 self assert:(bytes1 unsignedInt16At:3 MSB:false) = 16r4030. |
122 self assert:(bytes1 unsignedInt16At:3 MSB:false) = 16r4030. |
123 |
123 |
124 self assert:(bytes1 signedInt16At:1 MSB:true) = 16r1020. |
124 self assert:(bytes1 signedInt16At:1 MSB:true) = 16r1020. |
125 self assert:(bytes1 signedInt16At:1 MSB:false) = 16r2010. |
125 self assert:(bytes1 signedInt16At:1 MSB:false) = 16r2010. |
126 self assert:(bytes1 signedInt16At:2 MSB:true) = 16r2030. |
126 self assert:(bytes1 signedInt16At:2 MSB:true) = 16r2030. |
127 self assert:(bytes1 signedInt16At:2 MSB:false) = 16r3020. |
127 self assert:(bytes1 signedInt16At:2 MSB:false) = 16r3020. |
128 self assert:(bytes1 signedInt16At:3 MSB:true) = 16r3040. |
128 self assert:(bytes1 signedInt16At:3 MSB:true) = 16r3040. |
129 self assert:(bytes1 signedInt16At:3 MSB:false) = 16r4030. |
129 self assert:(bytes1 signedInt16At:3 MSB:false) = 16r4030. |
130 |
130 |
131 "/ bytes2 := #[ 16rFF 16r7F 16r80 16r81 ]. |
131 "/ bytes2 := #[ 16rFF 16r7F 16r80 16r81 ]. |
132 self assert:(bytes2 unsignedInt16At:1 MSB:true) = 16rFF7F. |
132 self assert:(bytes2 unsignedInt16At:1 MSB:true) = 16rFF7F. |
133 self assert:(bytes2 unsignedInt16At:1 MSB:false) = 16r7FFF. |
133 self assert:(bytes2 unsignedInt16At:1 MSB:false) = 16r7FFF. |
134 self assert:(bytes2 unsignedInt16At:2 MSB:true) = 16r7F80. |
134 self assert:(bytes2 unsignedInt16At:2 MSB:true) = 16r7F80. |
135 self assert:(bytes2 unsignedInt16At:2 MSB:false) = 16r807F. |
135 self assert:(bytes2 unsignedInt16At:2 MSB:false) = 16r807F. |
136 self assert:(bytes2 unsignedInt16At:3 MSB:true) = 16r8081. |
136 self assert:(bytes2 unsignedInt16At:3 MSB:true) = 16r8081. |
137 self assert:(bytes2 unsignedInt16At:3 MSB:false) = 16r8180. |
137 self assert:(bytes2 unsignedInt16At:3 MSB:false) = 16r8180. |
138 |
138 |
139 self assert:(bytes2 signedInt16At:1 MSB:true) = -129. "/ 16rFF7F signExtendedShortValue |
139 self assert:(bytes2 signedInt16At:1 MSB:true) = -129. "/ 16rFF7F signExtendedShortValue |
140 self assert:(bytes2 signedInt16At:1 MSB:false) = 16r7FFF. |
140 self assert:(bytes2 signedInt16At:1 MSB:false) = 16r7FFF. |
141 self assert:(bytes2 signedInt16At:2 MSB:true) = 16r7F80. |
141 self assert:(bytes2 signedInt16At:2 MSB:true) = 16r7F80. |
142 self assert:(bytes2 signedInt16At:2 MSB:false) = -32641. "/ 16r807F signExtendedShortValue. |
142 self assert:(bytes2 signedInt16At:2 MSB:false) = -32641. "/ 16r807F signExtendedShortValue. |
143 self assert:(bytes2 signedInt16At:3 MSB:true) = -32639. "/ 16r8081 signExtendedShortValue. |
143 self assert:(bytes2 signedInt16At:3 MSB:true) = -32639. "/ 16r8081 signExtendedShortValue. |
144 self assert:(bytes2 signedInt16At:3 MSB:false) = -32384. "/ 16r8180 signExtendedShortValue. |
144 self assert:(bytes2 signedInt16At:3 MSB:false) = -32384. "/ 16r8180 signExtendedShortValue. |
145 |
145 |
146 wBytes := bytes2 copy. |
146 wBytes := bytes2 copy. |
147 |
147 |
148 wBytes unsignedInt16At:1 put:16r1020 MSB:false. |
148 wBytes unsignedInt16At:1 put:16r1020 MSB:false. |
149 self assert:(wBytes unsignedInt16At:1 MSB:false) = 16r1020. |
149 self assert:(wBytes unsignedInt16At:1 MSB:false) = 16r1020. |
150 self assert:(wBytes signedInt16At:1 MSB:false) = 16r1020. |
150 self assert:(wBytes signedInt16At:1 MSB:false) = 16r1020. |
151 |
151 |
152 wBytes unsignedInt16At:1 put:16r1020 MSB:true. |
152 wBytes unsignedInt16At:1 put:16r1020 MSB:true. |
153 self assert:(wBytes unsignedInt16At:1 MSB:false) = 16r2010. |
153 self assert:(wBytes unsignedInt16At:1 MSB:false) = 16r2010. |
154 self assert:(wBytes signedInt16At:1 MSB:false) = 16r2010. |
154 self assert:(wBytes signedInt16At:1 MSB:false) = 16r2010. |
155 |
155 |
156 wBytes unsignedInt16At:1 put:16rFFFE MSB:false. |
156 wBytes unsignedInt16At:1 put:16rFFFE MSB:false. |
157 self assert:(wBytes unsignedInt16At:1 MSB:false) = 16rFFFE. |
157 self assert:(wBytes unsignedInt16At:1 MSB:false) = 16rFFFE. |
158 self assert:(wBytes signedInt16At:1 MSB:false) = -2. |
158 self assert:(wBytes signedInt16At:1 MSB:false) = -2. |
159 |
159 |
160 wBytes unsignedInt16At:1 put:16rFFFE MSB:true. |
160 wBytes unsignedInt16At:1 put:16rFFFE MSB:true. |
161 self assert:(wBytes unsignedInt16At:1 MSB:false) = 16rFEFF. |
161 self assert:(wBytes unsignedInt16At:1 MSB:false) = 16rFEFF. |
162 self assert:(wBytes signedInt16At:1 MSB:false) = -257. "/ 16rFEFF signExtendedShortValue |
162 self assert:(wBytes signedInt16At:1 MSB:false) = -257. "/ 16rFEFF signExtendedShortValue |
163 |
163 |
164 wBytes signedInt16At:1 put:16r1020 MSB:false. |
164 wBytes signedInt16At:1 put:16r1020 MSB:false. |
165 self assert:(wBytes unsignedInt16At:1 MSB:false) = 16r1020. |
165 self assert:(wBytes unsignedInt16At:1 MSB:false) = 16r1020. |
166 self assert:(wBytes signedInt16At:1 MSB:false) = 16r1020. |
166 self assert:(wBytes signedInt16At:1 MSB:false) = 16r1020. |
167 |
167 |
168 wBytes signedInt16At:1 put:16r1020 MSB:true. |
168 wBytes signedInt16At:1 put:16r1020 MSB:true. |
169 self assert:(wBytes unsignedInt16At:1 MSB:false) = 16r2010. |
169 self assert:(wBytes unsignedInt16At:1 MSB:false) = 16r2010. |
170 self assert:(wBytes signedInt16At:1 MSB:false) = 16r2010. |
170 self assert:(wBytes signedInt16At:1 MSB:false) = 16r2010. |
171 |
171 |
172 wBytes signedInt16At:1 put:-3 MSB:false. |
172 wBytes signedInt16At:1 put:-3 MSB:false. |
173 self assert:(wBytes unsignedInt16At:1 MSB:false) = 16rFFFD. |
173 self assert:(wBytes unsignedInt16At:1 MSB:false) = 16rFFFD. |
174 self assert:(wBytes signedInt16At:1 MSB:false) = -3. |
174 self assert:(wBytes signedInt16At:1 MSB:false) = -3. |
175 ]. |
175 ]. |
176 |
176 |
177 check |
177 check |
178 value: #[ 16r10 16r20 16r30 16r40 ] |
178 value: #[ 16r10 16r20 16r30 16r40 ] |
179 value: #[ 16rFF 16r7F 16r80 16r81 ]. |
179 value: #[ 16rFF 16r7F 16r80 16r81 ]. |
180 |
180 |
181 check |
181 check |
182 value: (WordArray with:16r2010 with:16r4030) |
182 value: (WordArray with:16r2010 with:16r4030) |
183 value: (WordArray with:16r7FFF with:16r8180). |
183 value: (WordArray with:16r7FFF with:16r8180). |
184 |
184 |
185 check |
185 check |
186 value: (IntegerArray with:16r40302010) |
186 value: (IntegerArray with:16r40302010) |
187 value: (IntegerArray with:16r81807FFF). |
187 value: (IntegerArray with:16r81807FFF). |
188 |
188 |
189 "/ check immutablility checks |
189 "/ check immutablility checks |
190 bytes := #[ 1 2 ] beImmutable. |
190 bytes := #[ 1 2 ] beImmutable. |
191 self |
191 self |
192 should:[ |
192 should:[ |
193 bytes unsignedInt16At:1 put:0 |
193 bytes unsignedInt16At:1 put:0 |
194 ] |
194 ] |
195 raise:NoModificationError. |
195 raise:NoModificationError. |
196 self assert:(bytes at:1) == 1. |
196 self assert:(bytes at:1) == 1. |
197 self assert:(bytes at:2) == 2. |
197 self assert:(bytes at:2) == 2. |
198 |
198 |
199 "/ check bounds checks |
199 "/ check bounds checks |
200 #(2 0 -1 -2) do:[:badIndex | |
200 #(2 0 -1 -2) do:[:badIndex | |
201 self |
201 self |
202 should:[ |
202 should:[ |
203 #[ 16rFF 16r00 ] unsignedInt16At:badIndex MSB:true |
203 #[ 16rFF 16r00 ] unsignedInt16At:badIndex MSB:true |
204 ] |
204 ] |
205 raise:SubscriptOutOfBoundsError. |
205 raise:SubscriptOutOfBoundsError. |
206 |
206 |
207 self |
207 self |
208 should:[ |
208 should:[ |
209 #[ 16rFF 16r00 ] unsignedInt16At:badIndex MSB:false |
209 #[ 16rFF 16r00 ] unsignedInt16At:badIndex MSB:false |
210 ] |
210 ] |
211 raise:SubscriptOutOfBoundsError. |
211 raise:SubscriptOutOfBoundsError. |
212 ] |
212 ] |
213 |
213 |
214 " |
214 " |
215 self run:#test01_int16Access |
215 self run:#test01_int16Access |
216 " |
216 " |