| 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 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 Int64 fact18 = _factorial(new Int64.fromInt(18)); | 522 Int64 fact18 = _factorial(new Int64.fromInt(18)); |
| 523 Int64 fact17 = _factorial(new Int64.fromInt(17)); | 523 Int64 fact17 = _factorial(new Int64.fromInt(17)); |
| 524 expect(fact18 ~/ fact17, new Int64.fromInt(18)); | 524 expect(fact18 ~/ fact17, new Int64.fromInt(18)); |
| 525 }); | 525 }); |
| 526 | 526 |
| 527 test("min, max values", () { | 527 test("min, max values", () { |
| 528 expect(new Int64.fromInt(1) << 63, Int64.MIN_VALUE); | 528 expect(new Int64.fromInt(1) << 63, Int64.MIN_VALUE); |
| 529 expect(-(Int64.MIN_VALUE + new Int64.fromInt(1)), Int64.MAX_VALUE); | 529 expect(-(Int64.MIN_VALUE + new Int64.fromInt(1)), Int64.MAX_VALUE); |
| 530 }); | 530 }); |
| 531 | 531 |
| 532 group("parse", () { |
| 533 test("parseRadix10", () { |
| 534 checkInt(int x) { |
| 535 expect(Int64.parseRadix('$x', 10), new Int64.fromInt(x)); |
| 536 } |
| 537 checkInt(0); |
| 538 checkInt(1); |
| 539 checkInt(-1); |
| 540 checkInt(1000); |
| 541 checkInt(12345678); |
| 542 checkInt(-12345678); |
| 543 checkInt(2147483647); |
| 544 checkInt(2147483648); |
| 545 checkInt(-2147483647); |
| 546 checkInt(-2147483648); |
| 547 checkInt(4294967295); |
| 548 checkInt(4294967296); |
| 549 checkInt(-4294967295); |
| 550 checkInt(-4294967296); |
| 551 }); |
| 552 |
| 553 test("parseRadix", () { |
| 554 check(String s, int r, String x) { |
| 555 expect(Int64.parseRadix(s, r).toString(), x); |
| 556 } |
| 557 check('ghoul', 36, '27699213'); |
| 558 check('ghoul', 35, '24769346'); |
| 559 // Min and max value. |
| 560 check("-9223372036854775808", 10, "-9223372036854775808"); |
| 561 check("9223372036854775807", 10, "9223372036854775807"); |
| 562 // Overflow during parsing. |
| 563 check("9223372036854775808", 10, "-9223372036854775808"); |
| 564 }); |
| 565 }); |
| 566 |
| 532 group("string representation", () { | 567 group("string representation", () { |
| 533 test("toString", () { | 568 test("toString", () { |
| 534 expect(new Int64.fromInt(0).toString(), "0"); | 569 expect(new Int64.fromInt(0).toString(), "0"); |
| 535 expect(new Int64.fromInt(1).toString(), "1"); | 570 expect(new Int64.fromInt(1).toString(), "1"); |
| 536 expect(new Int64.fromInt(-1).toString(), "-1"); | 571 expect(new Int64.fromInt(-1).toString(), "-1"); |
| 537 expect(new Int64.fromInt(-10).toString(), "-10"); | 572 expect(new Int64.fromInt(-10).toString(), "-10"); |
| 538 expect(Int64.MIN_VALUE.toString(), "-9223372036854775808"); | 573 expect(Int64.MIN_VALUE.toString(), "-9223372036854775808"); |
| 539 expect(Int64.MAX_VALUE.toString(), "9223372036854775807"); | 574 expect(Int64.MAX_VALUE.toString(), "9223372036854775807"); |
| 540 | 575 |
| 541 int top = 922337201; | 576 int top = 922337201; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 564 "-2021110011022210012102010021220101220222"); | 599 "-2021110011022210012102010021220101220222"); |
| 565 expect(Int64.MIN_VALUE.toRadixString(4), | 600 expect(Int64.MIN_VALUE.toRadixString(4), |
| 566 "-20000000000000000000000000000000"); | 601 "-20000000000000000000000000000000"); |
| 567 expect(Int64.MIN_VALUE.toRadixString(5), "-1104332401304422434310311213"); | 602 expect(Int64.MIN_VALUE.toRadixString(5), "-1104332401304422434310311213"); |
| 568 expect(Int64.MIN_VALUE.toRadixString(6), "-1540241003031030222122212"); | 603 expect(Int64.MIN_VALUE.toRadixString(6), "-1540241003031030222122212"); |
| 569 expect(Int64.MIN_VALUE.toRadixString(7), "-22341010611245052052301"); | 604 expect(Int64.MIN_VALUE.toRadixString(7), "-22341010611245052052301"); |
| 570 expect(Int64.MIN_VALUE.toRadixString(8), "-1000000000000000000000"); | 605 expect(Int64.MIN_VALUE.toRadixString(8), "-1000000000000000000000"); |
| 571 expect(Int64.MIN_VALUE.toRadixString(9), "-67404283172107811828"); | 606 expect(Int64.MIN_VALUE.toRadixString(9), "-67404283172107811828"); |
| 572 expect(Int64.MIN_VALUE.toRadixString(10), "-9223372036854775808"); | 607 expect(Int64.MIN_VALUE.toRadixString(10), "-9223372036854775808"); |
| 573 expect(Int64.MIN_VALUE.toRadixString(11), "-1728002635214590698"); | 608 expect(Int64.MIN_VALUE.toRadixString(11), "-1728002635214590698"); |
| 574 expect(Int64.MIN_VALUE.toRadixString(12), "-41A792678515120368"); | 609 expect(Int64.MIN_VALUE.toRadixString(12), "-41a792678515120368"); |
| 575 expect(Int64.MIN_VALUE.toRadixString(13), "-10B269549075433C38"); | 610 expect(Int64.MIN_VALUE.toRadixString(13), "-10b269549075433c38"); |
| 576 expect(Int64.MIN_VALUE.toRadixString(14), "-4340724C6C71DC7A8"); | 611 expect(Int64.MIN_VALUE.toRadixString(14), "-4340724c6c71dc7a8"); |
| 577 expect(Int64.MIN_VALUE.toRadixString(15), "-160E2AD3246366808"); | 612 expect(Int64.MIN_VALUE.toRadixString(15), "-160e2ad3246366808"); |
| 578 expect(Int64.MIN_VALUE.toRadixString(16), "-8000000000000000"); | 613 expect(Int64.MIN_VALUE.toRadixString(16), "-8000000000000000"); |
| 579 expect(Int64.MAX_VALUE.toRadixString(2), | 614 expect(Int64.MAX_VALUE.toRadixString(2), |
| 580 "111111111111111111111111111111111111111111111111111111111111111"); | 615 "111111111111111111111111111111111111111111111111111111111111111"); |
| 581 expect(Int64.MAX_VALUE.toRadixString(3), | 616 expect(Int64.MAX_VALUE.toRadixString(3), |
| 582 "2021110011022210012102010021220101220221"); | 617 "2021110011022210012102010021220101220221"); |
| 583 expect(Int64.MAX_VALUE.toRadixString(4), | 618 expect(Int64.MAX_VALUE.toRadixString(4), |
| 584 "13333333333333333333333333333333"); | 619 "13333333333333333333333333333333"); |
| 585 expect(Int64.MAX_VALUE.toRadixString(5), "1104332401304422434310311212"); | 620 expect(Int64.MAX_VALUE.toRadixString(5), "1104332401304422434310311212"); |
| 586 expect(Int64.MAX_VALUE.toRadixString(6), "1540241003031030222122211"); | 621 expect(Int64.MAX_VALUE.toRadixString(6), "1540241003031030222122211"); |
| 587 expect(Int64.MAX_VALUE.toRadixString(7), "22341010611245052052300"); | 622 expect(Int64.MAX_VALUE.toRadixString(7), "22341010611245052052300"); |
| 588 expect(Int64.MAX_VALUE.toRadixString(8), "777777777777777777777"); | 623 expect(Int64.MAX_VALUE.toRadixString(8), "777777777777777777777"); |
| 589 expect(Int64.MAX_VALUE.toRadixString(9), "67404283172107811827"); | 624 expect(Int64.MAX_VALUE.toRadixString(9), "67404283172107811827"); |
| 590 expect(Int64.MAX_VALUE.toRadixString(10), "9223372036854775807"); | 625 expect(Int64.MAX_VALUE.toRadixString(10), "9223372036854775807"); |
| 591 expect(Int64.MAX_VALUE.toRadixString(11), "1728002635214590697"); | 626 expect(Int64.MAX_VALUE.toRadixString(11), "1728002635214590697"); |
| 592 expect(Int64.MAX_VALUE.toRadixString(12), "41A792678515120367"); | 627 expect(Int64.MAX_VALUE.toRadixString(12), "41a792678515120367"); |
| 593 expect(Int64.MAX_VALUE.toRadixString(13), "10B269549075433C37"); | 628 expect(Int64.MAX_VALUE.toRadixString(13), "10b269549075433c37"); |
| 594 expect(Int64.MAX_VALUE.toRadixString(14), "4340724C6C71DC7A7"); | 629 expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7"); |
| 595 expect(Int64.MAX_VALUE.toRadixString(15), "160E2AD3246366807"); | 630 expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807"); |
| 596 expect(Int64.MAX_VALUE.toRadixString(16), "7FFFFFFFFFFFFFFF"); | 631 expect(Int64.MAX_VALUE.toRadixString(16), "7fffffffffffffff"); |
| 597 }); | 632 }); |
| 598 }); | 633 }); |
| 599 } | 634 } |
| OLD | NEW |