| 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.dart"); | 7 #library("MediumIntegerTest.dart"); |
| 8 #import("dart:coreimpl"); | 8 #import("dart:coreimpl"); |
| 9 | 9 |
| 10 |
| 10 class MediumIntegerTest { | 11 class MediumIntegerTest { |
| 11 | 12 |
| 12 static void checkSmi(int a) { | 13 static void checkSmi(int a) { |
| 13 Expect.equals(true, (a is Smi)); | 14 Expect.isTrue(a is Smi); |
| 14 } | 15 } |
| 15 | 16 |
| 16 static void checkMint(int a) { | 17 static void checkMint(int a) { |
| 17 Expect.equals(true, (a is Mint)); | 18 if (runsOn32Bit) { |
| 19 Expect.isTrue(a is Mint); |
| 20 } |
| 18 } | 21 } |
| 19 | 22 |
| 20 static void checkBigint(int a) { | 23 static void checkBigint(int a) { |
| 21 Expect.equals(true, (a is Bigint)); | 24 Expect.isTrue(a is Bigint); |
| 22 } | 25 } |
| 23 | 26 |
| 24 static int getMint() { | 27 static int getMint() { |
| 25 return 1234567890123456789; | 28 return 1234567890123456789; |
| 26 } | 29 } |
| 27 | 30 |
| 28 static testSmiOverflow() { | 31 static testSmiOverflow() { |
| 29 int a = 1073741823; | 32 int a = 1073741823; |
| 30 int b = 1073741822; | 33 int b = 1073741822; |
| 31 checkSmi(a); | 34 checkSmi(a); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 Expect.equals(4611686018427387904000000000000000000, a * b); | 133 Expect.equals(4611686018427387904000000000000000000, a * b); |
| 131 } | 134 } |
| 132 | 135 |
| 133 static testMintAnd(mint) { | 136 static testMintAnd(mint) { |
| 134 // Issue 1845. | 137 // Issue 1845. |
| 135 final int t = 0; | 138 final int t = 0; |
| 136 var res = mint & (t - 1); | 139 var res = mint & (t - 1); |
| 137 Expect.equals(mint, res); | 140 Expect.equals(mint, res); |
| 138 } | 141 } |
| 139 | 142 |
| 140 // TODO(srdjan): Add more tests. | 143 // Mint both in 32- and 64-bit architecture. |
| 144 static void testAlwaysMint() { |
| 145 var a = 4611686018427390000; |
| 146 Expect.isTrue(a is Mint); |
| 147 } |
| 141 | 148 |
| 142 static void testMain() { | 149 static void testMain() { |
| 143 checkMint(getMint()); | 150 checkMint(getMint()); |
| 144 Expect.equals(1234567890123456789, getMint()); | 151 Expect.equals(1234567890123456789, getMint()); |
| 145 testSmiOverflow(); | 152 testSmiOverflow(); |
| 146 testMintAdd(); | 153 testMintAdd(); |
| 147 testMintSub(); | 154 testMintSub(); |
| 148 testMintMul(); | 155 testMintMul(); |
| 149 testMintDiv(); | 156 testMintDiv(); |
| 150 testMintAnd(-1925149952); | 157 testMintAnd(-1925149952); |
| 151 testMintAnd(1925149952); | 158 testMintAnd(1925149952); |
| 152 var a = 100000000000; | 159 var a = 100000000000; |
| 153 var b = 100000000001; | 160 var b = 100000000001; |
| 154 checkMint(a); | 161 checkMint(a); |
| 155 checkMint(b); | 162 checkMint(b); |
| 156 Expect.equals(false, a.hashCode() == b.hashCode()); | 163 Expect.equals(false, a.hashCode() == b.hashCode()); |
| 157 Expect.equals(true, a.hashCode() == (b - 1).hashCode()); | 164 Expect.equals(true, a.hashCode() == (b - 1).hashCode()); |
| 165 testAlwaysMint(); |
| 158 } | 166 } |
| 159 } | 167 } |
| 160 | 168 |
| 169 bool runsOn32Bit; |
| 170 |
| 161 main() { | 171 main() { |
| 172 runsOn32Bit = 4294967295 is Mint; |
| 162 for (int i = 0; i < 1000; i++) { | 173 for (int i = 0; i < 1000; i++) { |
| 163 MediumIntegerTest.testMain(); | 174 MediumIntegerTest.testMain(); |
| 164 } | 175 } |
| 165 } | 176 } |
| OLD | NEW |