dart-sdk/tests/corelib_2/integer_arith_vm_test.dart
Alexander Markov a211134136 [Tests] Update _2 tests for Dart 2.0 fixed-size integers
Also, --limit-ints-to-64-bits is enabled when running tests in _2 test
suites.

This is the re-landing of 92ebd8aefa with
fixes:

* Revert changes in pkg/dev_compiler/test/browser/language_tests.js
  and tests/language/language_dart2js.status as they describe
  'language' test suite, not 'language_2'

* Correct tests/standalone_2/io/fuzz_support.dart as file_fuzz test was
  timing out on Windows and failing on android/arm.

Closes https://github.com/dart-lang/sdk/issues/31396

Change-Id: If9ca77fca300ddc605f17a7be39d1707e9724e25
Reviewed-on: https://dart-review.googlesource.com/21700
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2017-11-17 20:28:06 +00:00

140 lines
3 KiB
Dart

// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Testing integers with and without intrinsics.
// VMOptions=
// VMOptions=--no_intrinsify
// VMOptions=--optimization_counter_threshold=10 --no-background_compilation
library integer_arithmetic_test;
import "package:expect/expect.dart";
foo() => 1234567890123456789;
testSmiOverflow() {
var a = 1073741823;
var b = 1073741822;
Expect.equals(2147483645, a + b);
a = -1000000000;
b = 1000000001;
Expect.equals(-2000000001, a - b);
Expect.equals(-1000000001000000000, a * b);
}
testModPow() {
var x, e, m;
x = 1234567890;
e = 1000000001;
m = 19;
Expect.equals(11, x.modPow(e, m));
x = 1234567890;
e = 19;
m = 1000000001;
Expect.equals(122998977, x.modPow(e, m));
x = 19;
e = 1234567890;
m = 1000000001;
Expect.equals(619059596, x.modPow(e, m));
x = 19;
e = 1000000001;
m = 1234567890;
Expect.equals(84910879, x.modPow(e, m));
x = 1000000001;
e = 19;
m = 1234567890;
Expect.equals(872984351, x.modPow(e, m));
x = 1000000001;
e = 1234567890;
m = 19;
Expect.equals(0, x.modPow(e, m));
}
testModInverse() {
var x, m;
x = 1;
m = 1;
Expect.equals(0, x.modInverse(m));
x = 0;
m = 1000000001;
Expect.throws(() => x.modInverse(m), (e) => e is Exception); // Not coprime.
x = 1234567890;
m = 19;
Expect.equals(11, x.modInverse(m));
x = 1234567890;
m = 1000000001;
Expect.equals(189108911, x.modInverse(m));
x = 19;
m = 1000000001;
Expect.throws(() => x.modInverse(m), (e) => e is Exception); // Not coprime.
x = 19;
m = 1234567890;
Expect.equals(519818059, x.modInverse(m));
x = 1000000001;
m = 1234567890;
Expect.equals(1001100101, x.modInverse(m));
x = 1000000001;
m = 19;
Expect.throws(() => x.modInverse(m), (e) => e is Exception); // Not coprime.
}
testGcd() {
var x, m;
x = 1;
m = 1;
Expect.equals(1, x.gcd(m));
x = 693;
m = 609;
Expect.equals(21, x.gcd(m));
x = 693 << 40;
m = 609 << 40;
Expect.equals(21 << 40, x.gcd(m));
x = 609 << 40;
m = 693 << 40;
Expect.equals(21 << 40, x.gcd(m));
x = 0;
m = 1000000001;
Expect.equals(m, x.gcd(m));
x = 1000000001;
m = 0;
Expect.equals(x, x.gcd(m));
x = 0;
m = -1000000001;
Expect.equals(-m, x.gcd(m));
x = -1000000001;
m = 0;
Expect.equals(-x, x.gcd(m));
x = 0;
m = 0;
Expect.equals(0, x.gcd(m));
x = 1234567890;
m = 19;
Expect.equals(1, x.gcd(m));
x = 1234567890;
m = 1000000001;
Expect.equals(1, x.gcd(m));
x = 19;
m = 1000000001;
Expect.equals(19, x.gcd(m));
x = 19;
m = 1234567890;
Expect.equals(1, x.gcd(m));
x = 1000000001;
m = 1234567890;
Expect.equals(1, x.gcd(m));
x = 1000000001;
m = 19;
Expect.equals(19, x.gcd(m));
}
main() {
for (int i = 0; i < 10; i++) {
Expect.equals(1234567890123456789, foo());
testSmiOverflow();
testModPow(); // //# modPow: ok
testModInverse();
testGcd();
}
}