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('../fixnum.dart'); | 6 #import('../fixnum.dart'); |
7 | 7 |
8 void main() { | 8 void main() { |
9 testAdditive(); | 9 testAdditive(); |
10 testBitOps(); | 10 testBitOps(); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 Expect.isTrue(largePos <= largePos); | 135 Expect.isTrue(largePos <= largePos); |
136 Expect.isTrue(largePos == largePos); | 136 Expect.isTrue(largePos == largePos); |
137 Expect.isTrue(largePos >= largePos); | 137 Expect.isTrue(largePos >= largePos); |
138 Expect.isTrue(!(largePos > largePos)); | 138 Expect.isTrue(!(largePos > largePos)); |
139 | 139 |
140 Expect.isTrue(!(largePosPlusOne < largePos)); | 140 Expect.isTrue(!(largePosPlusOne < largePos)); |
141 Expect.isTrue(!(largePosPlusOne <= largePos)); | 141 Expect.isTrue(!(largePosPlusOne <= largePos)); |
142 Expect.isTrue(!(largePosPlusOne == largePos)); | 142 Expect.isTrue(!(largePosPlusOne == largePos)); |
143 Expect.isTrue(largePosPlusOne >= largePos); | 143 Expect.isTrue(largePosPlusOne >= largePos); |
144 Expect.isTrue(largePosPlusOne > largePos); | 144 Expect.isTrue(largePosPlusOne > largePos); |
145 | 145 |
146 try { | 146 try { |
147 new int64.fromInt(17) < null; | 147 new int64.fromInt(17) < null; |
148 Expect.fail("x < null should throw NullPointerException"); | 148 Expect.fail("x < null should throw NullPointerException"); |
149 } catch (NullPointerException e) { | 149 } on NullPointerException catch (e) { |
150 } | 150 } |
151 | 151 |
152 try { | 152 try { |
153 new int64.fromInt(17) <= null; | 153 new int64.fromInt(17) <= null; |
154 Expect.fail("x <= null should throw NullPointerException"); | 154 Expect.fail("x <= null should throw NullPointerException"); |
155 } catch (NullPointerException e) { | 155 } on NullPointerException catch (e) { |
156 } | 156 } |
157 | 157 |
158 try { | 158 try { |
159 new int64.fromInt(17) > null; | 159 new int64.fromInt(17) > null; |
160 Expect.fail("x > null should throw NullPointerException"); | 160 Expect.fail("x > null should throw NullPointerException"); |
161 } catch (NullPointerException e) { | 161 } on NullPointerException catch (e) { |
162 } | 162 } |
163 | 163 |
164 try { | 164 try { |
165 new int64.fromInt(17) < null; | 165 new int64.fromInt(17) < null; |
166 Expect.fail("x >= null should throw NullPointerException"); | 166 Expect.fail("x >= null should throw NullPointerException"); |
167 } catch (NullPointerException e) { | 167 } on NullPointerException catch (e) { |
168 } | 168 } |
169 | 169 |
170 Expect.isFalse(new int64.fromInt(17) == null); | 170 Expect.isFalse(new int64.fromInt(17) == null); |
171 } | 171 } |
172 | 172 |
173 void testConversions() { | 173 void testConversions() { |
174 Expect.equals(0, new int64.fromInt(0).toInt()); | 174 Expect.equals(0, new int64.fromInt(0).toInt()); |
175 Expect.equals(100, new int64.fromInt(100).toInt()); | 175 Expect.equals(100, new int64.fromInt(100).toInt()); |
176 Expect.equals(-100, new int64.fromInt(-100).toInt()); | 176 Expect.equals(-100, new int64.fromInt(-100).toInt()); |
177 Expect.equals(2147483647, new int64.fromInt(2147483647).toInt()); | 177 Expect.equals(2147483647, new int64.fromInt(2147483647).toInt()); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 Expect.equals(new int64.fromInt(-333), new int64.fromInt(-1000) ~/ | 370 Expect.equals(new int64.fromInt(-333), new int64.fromInt(-1000) ~/ |
371 new int64.fromInt(3)); | 371 new int64.fromInt(3)); |
372 Expect.equals(new int64.fromInt(333), new int64.fromInt(-1000) ~/ | 372 Expect.equals(new int64.fromInt(333), new int64.fromInt(-1000) ~/ |
373 new int64.fromInt(-3)); | 373 new int64.fromInt(-3)); |
374 Expect.equals(new int64.fromInt(0), new int64.fromInt(3) ~/ | 374 Expect.equals(new int64.fromInt(0), new int64.fromInt(3) ~/ |
375 new int64.fromInt(1000)); | 375 new int64.fromInt(1000)); |
376 Expect.equals(new int64.fromInts(0x1003d0, 0xe84f5ae8), new int64.fromInts( | 376 Expect.equals(new int64.fromInts(0x1003d0, 0xe84f5ae8), new int64.fromInts( |
377 0x12345678, 0x12345678) ~/ new int64.fromInts(0x0, 0x123)); | 377 0x12345678, 0x12345678) ~/ new int64.fromInts(0x0, 0x123)); |
378 Expect.equals(new int64.fromInts(0x0, 0x10003), new int64.fromInts( | 378 Expect.equals(new int64.fromInts(0x0, 0x10003), new int64.fromInts( |
379 0x12345678, 0x12345678) ~/ new int64.fromInts(0x1234, 0x12345678)); | 379 0x12345678, 0x12345678) ~/ new int64.fromInts(0x1234, 0x12345678)); |
380 Expect.equals(new int64.fromInts(0xffffffff, 0xffff3dfe), | 380 Expect.equals(new int64.fromInts(0xffffffff, 0xffff3dfe), |
381 new int64.fromInts(0xf2345678, 0x12345678) ~/ | 381 new int64.fromInts(0xf2345678, 0x12345678) ~/ |
382 new int64.fromInts(0x1234, 0x12345678)); | 382 new int64.fromInts(0x1234, 0x12345678)); |
383 Expect.equals(new int64.fromInts(0x0, 0xeda), new int64.fromInts(0xf2345678, | 383 Expect.equals(new int64.fromInts(0x0, 0xeda), new int64.fromInts(0xf2345678, |
384 0x12345678) ~/ new int64.fromInts(0xffff1234, 0x12345678)); | 384 0x12345678) ~/ new int64.fromInts(0xffff1234, 0x12345678)); |
385 | 385 |
386 try { | 386 try { |
387 new int64.fromInt(1) ~/ new int64.fromInt(0); | 387 new int64.fromInt(1) ~/ new int64.fromInt(0); |
388 Expect.fail("Expected an IntegerDivisionByZeroException"); | 388 Expect.fail("Expected an IntegerDivisionByZeroException"); |
389 } catch (IntegerDivisionByZeroException e) { | 389 } on IntegerDivisionByZeroException catch (e) { |
390 } | 390 } |
391 | 391 |
392 Expect.equals(new int64.fromInts(0xc0000000, 0x00000000), | 392 Expect.equals(new int64.fromInts(0xc0000000, 0x00000000), |
393 int64.MIN_VALUE ~/ new int64.fromInt(2)); | 393 int64.MIN_VALUE ~/ new int64.fromInt(2)); |
394 Expect.equals(int64.MIN_VALUE, int64.MIN_VALUE ~/ | 394 Expect.equals(int64.MIN_VALUE, int64.MIN_VALUE ~/ |
395 new int64.fromInt(1)); | 395 new int64.fromInt(1)); |
396 Expect.equals(int64.MIN_VALUE, int64.MIN_VALUE ~/ | 396 Expect.equals(int64.MIN_VALUE, int64.MIN_VALUE ~/ |
397 new int64.fromInt(-1)); | 397 new int64.fromInt(-1)); |
398 } | 398 } |
399 | 399 |
400 void testNegate() { | 400 void testNegate() { |
401 Expect.equals(new int64.fromInt(-1), -new int64.fromInt(1)); | 401 Expect.equals(new int64.fromInt(-1), -new int64.fromInt(1)); |
402 Expect.equals(new int64.fromInt(1), -new int64.fromInt(-1)); | 402 Expect.equals(new int64.fromInt(1), -new int64.fromInt(-1)); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 Expect.equals(new int64.fromInts(0x00000000, 0x00923456), | 509 Expect.equals(new int64.fromInts(0x00000000, 0x00923456), |
510 new int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(40)); | 510 new int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(40)); |
511 Expect.equals(new int64.fromInts(0x00000000, 0x00092345), | 511 Expect.equals(new int64.fromInts(0x00000000, 0x00092345), |
512 new int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(44)); | 512 new int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(44)); |
513 Expect.equals(new int64.fromInts(0x00000000, 0x00009234), | 513 Expect.equals(new int64.fromInts(0x00000000, 0x00009234), |
514 new int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(48)); | 514 new int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(48)); |
515 | 515 |
516 try { | 516 try { |
517 new int64.fromInt(17) >> -1; | 517 new int64.fromInt(17) >> -1; |
518 Expect.fail("x >> -1 should throw IllegalArgumentException"); | 518 Expect.fail("x >> -1 should throw IllegalArgumentException"); |
519 } catch (IllegalArgumentException e) { | 519 } on IllegalArgumentException catch (e) { |
520 } | 520 } |
521 | 521 |
522 try { | 522 try { |
523 new int64.fromInt(17) << -1; | 523 new int64.fromInt(17) << -1; |
524 Expect.fail("x >> -1 should throw IllegalArgumentException"); | 524 Expect.fail("x >> -1 should throw IllegalArgumentException"); |
525 } catch (IllegalArgumentException e) { | 525 } on IllegalArgumentException catch (e) { |
526 } | 526 } |
527 | 527 |
528 try { | 528 try { |
529 new int64.fromInt(17).shiftRightUnsigned(-1); | 529 new int64.fromInt(17).shiftRightUnsigned(-1); |
530 Expect.fail("x >> -1 should throw IllegalArgumentException"); | 530 Expect.fail("x >> -1 should throw IllegalArgumentException"); |
531 } catch (IllegalArgumentException e) { | 531 } on IllegalArgumentException catch (e) { |
532 } | 532 } |
533 | 533 |
534 } | 534 } |
535 | 535 |
536 void testToHexString() { | 536 void testToHexString() { |
537 int64 deadbeef12341234 = new int64.fromInts(0xDEADBEEF, 0x12341234); | 537 int64 deadbeef12341234 = new int64.fromInts(0xDEADBEEF, 0x12341234); |
538 Expect.equals("0", int64.ZERO.toHexString()); | 538 Expect.equals("0", int64.ZERO.toHexString()); |
539 Expect.equals("DEADBEEF12341234", deadbeef12341234.toHexString()); | 539 Expect.equals("DEADBEEF12341234", deadbeef12341234.toHexString()); |
540 } | 540 } |
541 | 541 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 Expect.equals("777777777777777777777", int64.MAX_VALUE.toRadixString(8)); | 597 Expect.equals("777777777777777777777", int64.MAX_VALUE.toRadixString(8)); |
598 Expect.equals("67404283172107811827", int64.MAX_VALUE.toRadixString(9)); | 598 Expect.equals("67404283172107811827", int64.MAX_VALUE.toRadixString(9)); |
599 Expect.equals("9223372036854775807", int64.MAX_VALUE.toRadixString(10)); | 599 Expect.equals("9223372036854775807", int64.MAX_VALUE.toRadixString(10)); |
600 Expect.equals("1728002635214590697", int64.MAX_VALUE.toRadixString(11)); | 600 Expect.equals("1728002635214590697", int64.MAX_VALUE.toRadixString(11)); |
601 Expect.equals("41A792678515120367", int64.MAX_VALUE.toRadixString(12)); | 601 Expect.equals("41A792678515120367", int64.MAX_VALUE.toRadixString(12)); |
602 Expect.equals("10B269549075433C37", int64.MAX_VALUE.toRadixString(13)); | 602 Expect.equals("10B269549075433C37", int64.MAX_VALUE.toRadixString(13)); |
603 Expect.equals("4340724C6C71DC7A7", int64.MAX_VALUE.toRadixString(14)); | 603 Expect.equals("4340724C6C71DC7A7", int64.MAX_VALUE.toRadixString(14)); |
604 Expect.equals("160E2AD3246366807", int64.MAX_VALUE.toRadixString(15)); | 604 Expect.equals("160E2AD3246366807", int64.MAX_VALUE.toRadixString(15)); |
605 Expect.equals("7FFFFFFFFFFFFFFF", int64.MAX_VALUE.toRadixString(16)); | 605 Expect.equals("7FFFFFFFFFFFFFFF", int64.MAX_VALUE.toRadixString(16)); |
606 } | 606 } |
OLD | NEW |