| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Testing Mints. Note that the tests may not work on 64-bit machines, | 4 // Testing Mints. Note that the tests may not work on 64-bit machines, |
| 5 // as Smi's would be used to represent many of the numbers. | 5 // as Smi's would be used to represent many of the numbers. |
| 6 | 6 |
| 7 library MediumIntegerTest; | 7 library MediumIntegerTest; |
| 8 |
| 8 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
| 9 | 10 |
| 10 | |
| 11 class MediumIntegerTest { | 11 class MediumIntegerTest { |
| 12 | |
| 13 static int getMint() { | 12 static int getMint() { |
| 14 return 1234567890123456789; | 13 return 1234567890123456789; |
| 15 } | 14 } |
| 16 | 15 |
| 17 static testSmiOverflow() { | 16 static testSmiOverflow() { |
| 18 int a = 1073741823; | 17 int a = 1073741823; |
| 19 int b = 1073741822; | 18 int b = 1073741822; |
| 20 Expect.equals(2147483645, a + b); | 19 Expect.equals(2147483645, a + b); |
| 21 Expect.equals(1152921501385621506, a * b); | 20 Expect.equals(1152921501385621506, a * b); |
| 22 Expect.equals(-2147483645, -a - b); | 21 Expect.equals(-2147483645, -a - b); |
| 23 } | 22 } |
| 24 | 23 |
| 25 static testMintAdd() { | 24 static testMintAdd() { |
| 26 // Mint and Smi. | 25 // Mint and Smi. |
| 27 var a = 1234567890123456789; | 26 var a = 1234567890123456789; |
| 28 var b = 2; | 27 var b = 2; |
| 29 Expect.equals(1234567890123456791, a + b); | 28 Expect.equals(1234567890123456791, a + b); |
| 30 Expect.equals(1234567890123456791, b + a); | 29 Expect.equals(1234567890123456791, b + a); |
| 31 a = 9223372036854775807; | 30 a = 9223372036854775807; |
| 32 Expect.equals(9223372036854775808, a + 1); | 31 Expect.equals(9223372036854775808, a + 1); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 Expect.equals(false, a.hashCode == b.hashCode); | 104 Expect.equals(false, a.hashCode == b.hashCode); |
| 106 Expect.equals(true, a.hashCode == (b - 1).hashCode); | 105 Expect.equals(true, a.hashCode == (b - 1).hashCode); |
| 107 } | 106 } |
| 108 } | 107 } |
| 109 | 108 |
| 110 main() { | 109 main() { |
| 111 for (int i = 0; i < 4000; i++) { | 110 for (int i = 0; i < 4000; i++) { |
| 112 MediumIntegerTest.testMain(); | 111 MediumIntegerTest.testMain(); |
| 113 } | 112 } |
| 114 } | 113 } |
| OLD | NEW |