dart-sdk/tests/corelib_2/integer_parsed_mul_div_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

82 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
library integer_arithmetic_test;
import "package:expect/expect.dart";
mulDivParsed(String a, String b, String product,
{String expected_quotient1, String expected_quotient2}) {
int int_a = int.parse(a);
int int_b = int.parse(b);
int int_product = int.parse(product);
int computed_product = int_a * int_b;
Expect.equals(int_product, computed_product);
String str_product = computed_product >= 0
? "0x${computed_product.toRadixString(16)}"
: "-0x${(-computed_product).toRadixString(16)}";
Expect.equals(product.toLowerCase(), str_product);
int computed_product2 = int_b * int_a;
Expect.equals(int_product, computed_product2);
String str_product2 = computed_product2 >= 0
? "0x${computed_product2.toRadixString(16)}"
: "-0x${(-computed_product2).toRadixString(16)}";
Expect.equals(product.toLowerCase(), str_product2);
if (int_a != 0) {
expected_quotient1 ??= b;
int int_expected_quotient1 = int.parse(expected_quotient1);
int computed_quotient1 = int_product ~/ int_a;
Expect.equals(int_expected_quotient1, computed_quotient1);
String str_quotient1 = computed_quotient1 >= 0
? "0x${computed_quotient1.toRadixString(16)}"
: "-0x${(-computed_quotient1).toRadixString(16)}";
Expect.equals(expected_quotient1.toLowerCase(), str_quotient1);
}
if (int_b != 0) {
expected_quotient2 ??= a;
int int_expected_quotient2 = int.parse(expected_quotient2);
int computed_quotient2 = int_product ~/ int_b;
Expect.equals(int_expected_quotient2, computed_quotient2);
String str_quotient2 = computed_quotient2 >= 0
? "0x${computed_quotient2.toRadixString(16)}"
: "-0x${(-computed_quotient2).toRadixString(16)}";
Expect.equals(expected_quotient2.toLowerCase(), str_quotient2);
}
}
testMultiplyDivide() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
mulDivParsed(zero, zero, zero);
mulDivParsed(one, one, one);
mulDivParsed(one, zero, zero);
mulDivParsed(zero, one, zero);
mulDivParsed(one, minus_one, minus_one);
mulDivParsed(minus_one, minus_one, one);
mulDivParsed("0x42", one, "0x42");
mulDivParsed("0x42", "0x2", "0x84");
mulDivParsed("0xFFFF", "0x2", "0x1FFFE");
mulDivParsed("0x3", "0x5", "0xF");
mulDivParsed("0xFFFFF", "0x5", "0x4FFFFB");
mulDivParsed("0xFFFFFFF", "0x5", "0x4FFFFFFB");
mulDivParsed("0xFFFFFFFF", "0x5", "0x4FFFFFFFB");
mulDivParsed("0x7FFFFFFFFFFFFFFF", "0x5", "0x7FFFFFFFFFFFFFFB",
expected_quotient1: zero, expected_quotient2: "0x1999999999999998");
mulDivParsed("0x7FFFFFFFFFFFFFFF", "0x3039", "0x7FFFFFFFFFFFCFC7",
expected_quotient1: zero, expected_quotient2: "0x2A783BE38C73D");
mulDivParsed("0x10000001", "0x5", "0x50000005");
}
main() {
testMultiplyDivide();
}