dart-sdk/tests/standalone_2/medium_integer_test.dart
Alexander Markov b6276eb3d5 [VM] Enable --limit-ints-to-64-bits in Dart 2.0 precompiler, v3.
* Enable --limit-ints-to-64-bits for CFE when it is used to generate
  kernel for VM as CFE relies on int.parse being able to parse correct
  literals and reject incorrect.

* Pass --limit-ints-to-64-bits to gen_kernel via environment
  variable to support batch mode compilation.

Issue: https://github.com/dart-lang/sdk/issues/31339

Re-landing https://dart-review.googlesource.com/29941 with the fix:

* Use checked-in SDK to avoid timeouts on SIMARM bots.
  Checked-in SDK was updated and now includes necessary fixes.

Change-Id: I4a5a99455b60204572f3d619d7eb374035b03e40
Reviewed-on: https://dart-review.googlesource.com/30640
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2017-12-20 18:04:42 +00:00

108 lines
2.7 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 Mints. Note that the tests may not work on 64-bit machines,
// as Smi's would be used to represent many of the numbers.
library MediumIntegerTest;
import "package:expect/expect.dart";
class MediumIntegerTest {
static int getMint() {
return 1234567890123456789;
}
static testSmiOverflow() {
int a = 1073741823;
int b = 1073741822;
Expect.equals(2147483645, a + b);
Expect.equals(1152921501385621506, a * b);
Expect.equals(-2147483645, -a - b);
}
static testMintAdd() {
// Mint and Smi.
var a = 1234567890123456789;
var b = 2;
Expect.equals(1234567890123456791, a + b);
Expect.equals(1234567890123456791, b + a);
a = 9223372036854775807;
Expect.equals(-9223372036854775808, a + 1);
// Mint and Mint.
a = 100000000000000001;
Expect.equals(200000000000000002, a + a);
a = 9223372036854775800;
b = 1000000000000000000;
Expect.equals(-8223372036854775816, a + b);
// Mint and double.
var da = 100000000000.0;
b = 100000000000;
Expect.equals(200000000000.0, da + b);
Expect.equals(200000000000.0, b + da);
}
static testMintSub() {
// Mint and Smi.
var a = 1234567890123456789;
var b = 2;
Expect.equals(1234567890123456787, a - b);
a = -9223372036854775808;
Expect.equals(9223372036854775807, a - 1);
// Mint and Mint.
a = 1234567890123456789;
b = 1000000000000000000;
Expect.equals(234567890123456789, a - b);
a = -9223372036854775808;
b = 1000000000000000000;
Expect.equals(8223372036854775808, a - b);
}
static testMintDiv() {
// Mint and Smi.
var a = 1234567890123456788;
var b = 2;
Expect.equals(617283945061728394.0, a / b);
}
static testMintMul() {
// Mint and Smi.
var a = 4611686018427387904;
var b = 10;
Expect.equals(-9223372036854775808, a * b);
b = 1000000000000000000;
Expect.equals(0, a * b);
}
static testMintAnd(mint) {
// Issue 1845.
final int t = 0;
var res = mint & (t - 1);
Expect.equals(mint, res);
}
static void testMain() {
Expect.equals(1234567890123456789, getMint());
testSmiOverflow();
testMintAdd();
testMintSub();
testMintMul();
testMintDiv();
testMintAnd(-1925149952);
testMintAnd(1925149952);
testMintAnd(0x100000001);
var a = 100000000000;
var b = 100000000001;
Expect.equals(false, a.hashCode == b.hashCode);
Expect.equals(true, a.hashCode == (b - 1).hashCode);
}
}
main() {
for (int i = 0; i < 4000; i++) {
MediumIntegerTest.testMain();
}
}