OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library int64test; | 5 library int64test; |
6 import 'package:fixnum/fixnum.dart'; | 6 import 'package:fixnum/fixnum.dart'; |
7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 | 8 |
9 void main() { | 9 void main() { |
10 group("arithmetic operators", () { | 10 group("arithmetic operators", () { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 new int32.fromInt(432461)); | 152 new int32.fromInt(432461)); |
153 expect(new int64.fromInt(829893893) ~/ 1919, | 153 expect(new int64.fromInt(829893893) ~/ 1919, |
154 new int32.fromInt(432461)); | 154 new int32.fromInt(432461)); |
155 expect(() => new int64.fromInt(1) ~/ new int64.fromInt(0), | 155 expect(() => new int64.fromInt(1) ~/ new int64.fromInt(0), |
156 throwsA(new isInstanceOf<IntegerDivisionByZeroException>())); | 156 throwsA(new isInstanceOf<IntegerDivisionByZeroException>())); |
157 expect(int64.MIN_VALUE ~/ new int64.fromInt(2), | 157 expect(int64.MIN_VALUE ~/ new int64.fromInt(2), |
158 new int64.fromInts(0xc0000000, 0x00000000)); | 158 new int64.fromInts(0xc0000000, 0x00000000)); |
159 expect(int64.MIN_VALUE ~/ new int64.fromInt(1), int64.MIN_VALUE); | 159 expect(int64.MIN_VALUE ~/ new int64.fromInt(1), int64.MIN_VALUE); |
160 expect(int64.MIN_VALUE ~/ new int64.fromInt(-1), int64.MIN_VALUE); | 160 expect(int64.MIN_VALUE ~/ new int64.fromInt(-1), int64.MIN_VALUE); |
161 expect(() => new int64.fromInt(17) ~/ int64.ZERO, throws); | 161 expect(() => new int64.fromInt(17) ~/ int64.ZERO, throws); |
162 expect(() => new int64.fromInt(17) ~/ null, throws); | 162 expect(() => new int64.fromInt(17) ~/ null, throwsArgumentError); |
163 }); | 163 }); |
164 | 164 |
165 test("%", () { | 165 test("%", () { |
166 // Define % as Euclidean mod, with positive result for all arguments | 166 // Define % as Euclidean mod, with positive result for all arguments |
167 expect(int64.ZERO % new int64.fromInt(1000), new int64.fromInt(0)); | 167 expect(int64.ZERO % new int64.fromInt(1000), new int64.fromInt(0)); |
168 expect(int64.MIN_VALUE % int64.MIN_VALUE, new int64.fromInt(0)); | 168 expect(int64.MIN_VALUE % int64.MIN_VALUE, new int64.fromInt(0)); |
169 expect(new int64.fromInt(1000) % int64.MIN_VALUE, | 169 expect(new int64.fromInt(1000) % int64.MIN_VALUE, |
170 new int64.fromInt(1000)); | 170 new int64.fromInt(1000)); |
171 expect(int64.MIN_VALUE % new int64.fromInt(8192), new int64.fromInt(0)); | 171 expect(int64.MIN_VALUE % new int64.fromInt(8192), new int64.fromInt(0)); |
172 expect(int64.MIN_VALUE % new int64.fromInt(8193), | 172 expect(int64.MIN_VALUE % new int64.fromInt(8193), |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 }); | 211 }); |
212 | 212 |
213 group("comparison operators", () { | 213 group("comparison operators", () { |
214 int64 largeNeg = new int64.fromInts(0x82341234, 0x0); | 214 int64 largeNeg = new int64.fromInts(0x82341234, 0x0); |
215 int64 largePos = new int64.fromInts(0x12341234, 0x0); | 215 int64 largePos = new int64.fromInts(0x12341234, 0x0); |
216 int64 largePosPlusOne = largePos + new int64.fromInt(1); | 216 int64 largePosPlusOne = largePos + new int64.fromInt(1); |
217 | 217 |
218 test("<", () { | 218 test("<", () { |
219 expect(new int64.fromInt(10) < new int64.fromInt(11), true); | 219 expect(new int64.fromInt(10) < new int64.fromInt(11), true); |
220 expect(new int64.fromInt(10) < new int64.fromInt(10), false); | 220 expect(new int64.fromInt(10) < new int64.fromInt(10), false); |
221 expect(new int64.fromInt(12) < new int64.fromInt(11), false); | 221 expect(new int64.fromInt(10) < new int64.fromInt(9), false); |
| 222 expect(new int64.fromInt(10) < new int32.fromInt(11), true); |
| 223 expect(new int64.fromInt(10) < new int32.fromInt(10), false); |
| 224 expect(new int64.fromInt(10) < new int32.fromInt(9), false); |
222 expect(new int64.fromInt(-10) < new int64.fromInt(-11), false); | 225 expect(new int64.fromInt(-10) < new int64.fromInt(-11), false); |
223 expect(int64.MIN_VALUE < new int64.fromInt(0), true); | 226 expect(int64.MIN_VALUE < new int64.fromInt(0), true); |
224 expect(largeNeg < largePos, true); | 227 expect(largeNeg < largePos, true); |
225 expect(largePos < largePosPlusOne, true); | 228 expect(largePos < largePosPlusOne, true); |
226 expect(largePos < largePos, false); | 229 expect(largePos < largePos, false); |
227 expect(largePosPlusOne < largePos, false); | 230 expect(largePosPlusOne < largePos, false); |
228 expect(int64.MIN_VALUE < int64.MAX_VALUE, true); | 231 expect(int64.MIN_VALUE < int64.MAX_VALUE, true); |
229 expect(int64.MAX_VALUE < int64.MIN_VALUE, false); | 232 expect(int64.MAX_VALUE < int64.MIN_VALUE, false); |
230 expect(() => new int64.fromInt(17) < null, throwsArgumentError); | 233 expect(() => new int64.fromInt(17) < null, throwsArgumentError); |
231 }); | 234 }); |
232 | 235 |
233 test("<=", () { | 236 test("<=", () { |
234 expect(new int64.fromInt(10) <= new int64.fromInt(11), true); | 237 expect(new int64.fromInt(10) <= new int64.fromInt(11), true); |
235 expect(new int64.fromInt(10) <= new int64.fromInt(10), true); | 238 expect(new int64.fromInt(10) <= new int64.fromInt(10), true); |
236 expect(new int64.fromInt(12) <= new int64.fromInt(11), false); | 239 expect(new int64.fromInt(10) <= new int64.fromInt(9), false); |
| 240 expect(new int64.fromInt(10) <= new int32.fromInt(11), true); |
| 241 expect(new int64.fromInt(10) <= new int32.fromInt(10), true); |
| 242 expect(new int64.fromInt(10) <= new int64.fromInt(9), false); |
237 expect(new int64.fromInt(-10) <= new int64.fromInt(-11), false); | 243 expect(new int64.fromInt(-10) <= new int64.fromInt(-11), false); |
238 expect(new int64.fromInt(-10) <= new int64.fromInt(-10), true); | 244 expect(new int64.fromInt(-10) <= new int64.fromInt(-10), true); |
239 expect(largeNeg <= largePos, true); | 245 expect(largeNeg <= largePos, true); |
240 expect(largePos <= largeNeg, false); | 246 expect(largePos <= largeNeg, false); |
241 expect(largePos <= largePosPlusOne, true); | 247 expect(largePos <= largePosPlusOne, true); |
242 expect(largePos <= largePos, true); | 248 expect(largePos <= largePos, true); |
243 expect(largePosPlusOne <= largePos, false); | 249 expect(largePosPlusOne <= largePos, false); |
244 expect(int64.MIN_VALUE <= int64.MAX_VALUE, true); | 250 expect(int64.MIN_VALUE <= int64.MAX_VALUE, true); |
245 expect(int64.MAX_VALUE <= int64.MIN_VALUE, false); | 251 expect(int64.MAX_VALUE <= int64.MIN_VALUE, false); |
246 expect(() => new int64.fromInt(17) <= null, throwsArgumentError); | 252 expect(() => new int64.fromInt(17) <= null, throwsArgumentError); |
247 }); | 253 }); |
248 | 254 |
249 test("==", () { | 255 test("==", () { |
250 expect(new int64.fromInt(10) == new int64.fromInt(11), false); | 256 expect(new int64.fromInt(10) == new int64.fromInt(11), false); |
251 expect(new int64.fromInt(10) == new int64.fromInt(10), true); | 257 expect(new int64.fromInt(10) == new int64.fromInt(10), true); |
252 expect(new int64.fromInt(12) == new int64.fromInt(11), false); | 258 expect(new int64.fromInt(10) == new int64.fromInt(9), false); |
| 259 expect(new int64.fromInt(10) == new int32.fromInt(11), false); |
| 260 expect(new int64.fromInt(10) == new int32.fromInt(10), true); |
| 261 expect(new int64.fromInt(10) == new int32.fromInt(9), false); |
253 expect(new int64.fromInt(-10) == new int64.fromInt(-10), true); | 262 expect(new int64.fromInt(-10) == new int64.fromInt(-10), true); |
254 expect(new int64.fromInt(-10) != new int64.fromInt(-10), false); | 263 expect(new int64.fromInt(-10) != new int64.fromInt(-10), false); |
255 expect(largePos == largePos, true); | 264 expect(largePos == largePos, true); |
256 expect(largePos == largePosPlusOne, false); | 265 expect(largePos == largePosPlusOne, false); |
257 expect(largePosPlusOne == largePos, false); | 266 expect(largePosPlusOne == largePos, false); |
258 expect(int64.MIN_VALUE == int64.MAX_VALUE, false); | 267 expect(int64.MIN_VALUE == int64.MAX_VALUE, false); |
| 268 expect(new int64.fromInt(17) == new Object(), false); |
259 expect(new int64.fromInt(17) == null, false); | 269 expect(new int64.fromInt(17) == null, false); |
260 }); | 270 }); |
261 | 271 |
262 test(">=", () { | 272 test(">=", () { |
263 expect(new int64.fromInt(10) >= new int64.fromInt(11), false); | 273 expect(new int64.fromInt(10) >= new int64.fromInt(11), false); |
264 expect(new int64.fromInt(10) >= new int64.fromInt(10), true); | 274 expect(new int64.fromInt(10) >= new int64.fromInt(10), true); |
265 expect(new int64.fromInt(12) >= new int64.fromInt(11), true); | 275 expect(new int64.fromInt(10) >= new int64.fromInt(9), true); |
| 276 expect(new int64.fromInt(10) >= new int32.fromInt(11), false); |
| 277 expect(new int64.fromInt(10) >= new int32.fromInt(10), true); |
| 278 expect(new int64.fromInt(10) >= new int32.fromInt(9), true); |
266 expect(new int64.fromInt(-10) >= new int64.fromInt(-11), true); | 279 expect(new int64.fromInt(-10) >= new int64.fromInt(-11), true); |
267 expect(new int64.fromInt(-10) >= new int64.fromInt(-10), true); | 280 expect(new int64.fromInt(-10) >= new int64.fromInt(-10), true); |
268 expect(largePos >= largeNeg, true); | 281 expect(largePos >= largeNeg, true); |
269 expect(largeNeg >= largePos, false); | 282 expect(largeNeg >= largePos, false); |
270 expect(largePos >= largePosPlusOne, false); | 283 expect(largePos >= largePosPlusOne, false); |
271 expect(largePos >= largePos, true); | 284 expect(largePos >= largePos, true); |
272 expect(largePosPlusOne >= largePos, true); | 285 expect(largePosPlusOne >= largePos, true); |
273 expect(int64.MIN_VALUE >= int64.MAX_VALUE, false); | 286 expect(int64.MIN_VALUE >= int64.MAX_VALUE, false); |
274 expect(int64.MAX_VALUE >= int64.MIN_VALUE, true); | 287 expect(int64.MAX_VALUE >= int64.MIN_VALUE, true); |
275 expect(() => new int64.fromInt(17) >= null, throwsArgumentError); | 288 expect(() => new int64.fromInt(17) >= null, throwsArgumentError); |
276 }); | 289 }); |
277 | 290 |
278 test(">", () { | 291 test(">", () { |
279 expect(new int64.fromInt(10) > new int64.fromInt(11), false); | 292 expect(new int64.fromInt(10) > new int64.fromInt(11), false); |
280 expect(new int64.fromInt(10) > new int64.fromInt(10), false); | 293 expect(new int64.fromInt(10) > new int64.fromInt(10), false); |
281 expect(new int64.fromInt(12) > new int64.fromInt(11), true); | 294 expect(new int64.fromInt(10) > new int64.fromInt(9), true); |
| 295 expect(new int64.fromInt(10) > new int32.fromInt(11), false); |
| 296 expect(new int64.fromInt(10) > new int32.fromInt(10), false); |
| 297 expect(new int64.fromInt(10) > new int32.fromInt(9), true); |
282 expect(new int64.fromInt(-10) > new int64.fromInt(-11), true); | 298 expect(new int64.fromInt(-10) > new int64.fromInt(-11), true); |
283 expect(new int64.fromInt(10) > new int64.fromInt(-11), true); | 299 expect(new int64.fromInt(10) > new int64.fromInt(-11), true); |
284 expect(new int64.fromInt(-10) > new int64.fromInt(11), false); | 300 expect(new int64.fromInt(-10) > new int64.fromInt(11), false); |
285 expect(largePos > largeNeg, true); | 301 expect(largePos > largeNeg, true); |
286 expect(largeNeg > largePos, false); | 302 expect(largeNeg > largePos, false); |
287 expect(largePos > largePosPlusOne, false); | 303 expect(largePos > largePosPlusOne, false); |
288 expect(largePos > largePos, false); | 304 expect(largePos > largePos, false); |
289 expect(largePosPlusOne > largePos, true); | 305 expect(largePosPlusOne > largePos, true); |
290 expect(new int64.fromInt(0) > int64.MIN_VALUE, true); | 306 expect(new int64.fromInt(0) > int64.MIN_VALUE, true); |
291 expect(int64.MIN_VALUE > int64.MAX_VALUE, false); | 307 expect(int64.MIN_VALUE > int64.MAX_VALUE, false); |
292 expect(int64.MAX_VALUE > int64.MIN_VALUE, true); | 308 expect(int64.MAX_VALUE > int64.MIN_VALUE, true); |
293 expect(() => new int64.fromInt(17) > null, throwsArgumentError); | 309 expect(() => new int64.fromInt(17) > null, throwsArgumentError); |
294 }); | 310 }); |
295 }); | 311 }); |
296 | 312 |
297 group("bitwise operators", () { | 313 group("bitwise operators", () { |
298 int64 n1 = new int64.fromInt(1234); | 314 int64 n1 = new int64.fromInt(1234); |
299 int64 n2 = new int64.fromInt(9876); | 315 int64 n2 = new int64.fromInt(9876); |
300 int64 n3 = new int64.fromInt(-1234); | 316 int64 n3 = new int64.fromInt(-1234); |
301 int64 n4 = new int64.fromInt(0x1234) << 32; | 317 int64 n4 = new int64.fromInt(0x1234) << 32; |
302 int64 n5 = new int64.fromInt(0x9876) << 32; | 318 int64 n5 = new int64.fromInt(0x9876) << 32; |
303 | 319 |
304 test("&", () { | 320 test("&", () { |
305 expect(n1 & n2, new int64.fromInt(1168)); | 321 expect(n1 & n2, new int64.fromInt(1168)); |
306 expect(n3 & n2, new int64.fromInt(8708)); | 322 expect(n3 & n2, new int64.fromInt(8708)); |
307 expect(n4 & n5, new int64.fromInt(0x1034) << 32); | 323 expect(n4 & n5, new int64.fromInt(0x1034) << 32); |
308 expect(() => n1 & null, throws); | 324 expect(() => n1 & null, throwsArgumentError); |
309 }); | 325 }); |
310 | 326 |
311 test("|", () { | 327 test("|", () { |
312 expect(n1 | n2, new int64.fromInt(9942)); | 328 expect(n1 | n2, new int64.fromInt(9942)); |
313 expect(n3 | n2, new int64.fromInt(-66)); | 329 expect(n3 | n2, new int64.fromInt(-66)); |
314 expect(n4 | n5, new int64.fromInt(0x9a76) << 32); | 330 expect(n4 | n5, new int64.fromInt(0x9a76) << 32); |
315 expect(() => n1 | null, throws); | 331 expect(() => n1 | null, throwsArgumentError); |
316 }); | 332 }); |
317 | 333 |
318 test("^", () { | 334 test("^", () { |
319 expect(n1 ^ n2, new int64.fromInt(8774)); | 335 expect(n1 ^ n2, new int64.fromInt(8774)); |
320 expect(n3 ^ n2, new int64.fromInt(-8774)); | 336 expect(n3 ^ n2, new int64.fromInt(-8774)); |
321 expect(n4 ^ n5, new int64.fromInt(0x8a42) << 32); | 337 expect(n4 ^ n5, new int64.fromInt(0x8a42) << 32); |
322 expect(() => n1 ^ null, throws); | 338 expect(() => n1 ^ null, throwsArgumentError); |
323 }); | 339 }); |
324 | 340 |
325 test("~", () { | 341 test("~", () { |
326 expect(-new int64.fromInt(1), new int64.fromInt(-1)); | 342 expect(-new int64.fromInt(1), new int64.fromInt(-1)); |
327 expect(-new int64.fromInt(-1), new int64.fromInt(1)); | 343 expect(-new int64.fromInt(-1), new int64.fromInt(1)); |
328 expect(-int64.MIN_VALUE, int64.MIN_VALUE); | 344 expect(-int64.MIN_VALUE, int64.MIN_VALUE); |
329 | 345 |
330 expect(~n1, new int64.fromInt(-1235)); | 346 expect(~n1, new int64.fromInt(-1235)); |
331 expect(~n2, new int64.fromInt(-9877)); | 347 expect(~n2, new int64.fromInt(-9877)); |
332 expect(~n3, new int64.fromInt(1233)); | 348 expect(~n3, new int64.fromInt(1233)); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 expect(int64.MAX_VALUE.toRadixString(10), "9223372036854775807"); | 590 expect(int64.MAX_VALUE.toRadixString(10), "9223372036854775807"); |
575 expect(int64.MAX_VALUE.toRadixString(11), "1728002635214590697"); | 591 expect(int64.MAX_VALUE.toRadixString(11), "1728002635214590697"); |
576 expect(int64.MAX_VALUE.toRadixString(12), "41A792678515120367"); | 592 expect(int64.MAX_VALUE.toRadixString(12), "41A792678515120367"); |
577 expect(int64.MAX_VALUE.toRadixString(13), "10B269549075433C37"); | 593 expect(int64.MAX_VALUE.toRadixString(13), "10B269549075433C37"); |
578 expect(int64.MAX_VALUE.toRadixString(14), "4340724C6C71DC7A7"); | 594 expect(int64.MAX_VALUE.toRadixString(14), "4340724C6C71DC7A7"); |
579 expect(int64.MAX_VALUE.toRadixString(15), "160E2AD3246366807"); | 595 expect(int64.MAX_VALUE.toRadixString(15), "160E2AD3246366807"); |
580 expect(int64.MAX_VALUE.toRadixString(16), "7FFFFFFFFFFFFFFF"); | 596 expect(int64.MAX_VALUE.toRadixString(16), "7FFFFFFFFFFFFFFF"); |
581 }); | 597 }); |
582 }); | 598 }); |
583 } | 599 } |
OLD | NEW |