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 | 4 |
5 // Testing Bigints with and without intrinsics. | 5 // Testing Bigints with and without intrinsics. |
6 // VMOptions= | 6 // VMOptions= |
7 // VMOptions=--no_intrinsify | 7 // VMOptions=--no_intrinsify |
| 8 // VMOptions=--optimization_counter_threshold=10 |
8 | 9 |
9 library big_integer_test; | 10 library big_integer_test; |
10 import "package:expect/expect.dart"; | 11 import "package:expect/expect.dart"; |
11 | 12 |
12 foo() => 1234567890123456789; | 13 foo() => 1234567890123456789; |
13 bar() => 12345678901234567890; | 14 bar() => 12345678901234567890; |
14 | 15 |
15 testSmiOverflow() { | 16 testSmiOverflow() { |
16 var a = 1073741823; | 17 var a = 1073741823; |
17 var b = 1073741822; | 18 var b = 1073741822; |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 bool exceptionCaught = false; | 390 bool exceptionCaught = false; |
390 try { | 391 try { |
391 var a = 1 << 1111111111111111111111111111; | 392 var a = 1 << 1111111111111111111111111111; |
392 } on OutOfMemoryError catch (e) { | 393 } on OutOfMemoryError catch (e) { |
393 exceptionCaught = true; | 394 exceptionCaught = true; |
394 } | 395 } |
395 Expect.equals(true, exceptionCaught); | 396 Expect.equals(true, exceptionCaught); |
396 } | 397 } |
397 | 398 |
398 main() { | 399 main() { |
399 Expect.equals(1234567890123456789, foo()); | 400 for (int i = 0; i < 10; i++) { |
400 Expect.equals(12345678901234567890, bar()); | 401 Expect.equals(1234567890123456789, foo()); |
401 testSmiOverflow(); | 402 Expect.equals(12345678901234567890, bar()); |
402 testBigintAdd(); | 403 testSmiOverflow(); /// overflow: ok |
403 testBigintSub(); | 404 testBigintAdd(); /// add: ok |
404 testBigintMul(); | 405 testBigintSub(); /// sub: ok |
405 testBigintTruncDiv(); | 406 testBigintMul(); /// mul: ok |
406 testBigintDiv(); | 407 testBigintTruncDiv(); /// trunDiv: ok |
407 testBigintModulo(); | 408 testBigintDiv(); /// div: ok |
408 testBigintModPow(); | 409 testBigintModulo(); /// mod: ok |
409 testBigintModInverse(); | 410 testBigintModPow(); /// modPow: ok |
410 testBigintGcd(); | 411 testBigintModInverse(); /// modInv: ok |
411 testBigintNegate(); | 412 testBigintGcd(); /// gcd: ok |
412 testShiftAmount(); | 413 testBigintNegate(); /// negate: ok |
413 Expect.equals(12345678901234567890, (12345678901234567890).abs()); | 414 testShiftAmount(); /// shift: ok |
414 Expect.equals(12345678901234567890, (-12345678901234567890).abs()); | 415 Expect.equals(12345678901234567890, (12345678901234567890).abs()); |
415 var a = 10000000000000000000; | 416 Expect.equals(12345678901234567890, (-12345678901234567890).abs()); |
416 var b = 10000000000000000001; | 417 var a = 10000000000000000000; |
417 Expect.equals(false, a.hashCode == b.hashCode); | 418 var b = 10000000000000000001; |
418 Expect.equals(true, a.hashCode == (b - 1).hashCode); | 419 Expect.equals(false, a.hashCode == b.hashCode); |
| 420 Expect.equals(true, a.hashCode == (b - 1).hashCode); |
| 421 } |
419 } | 422 } |
OLD | NEW |