Migrate test block 1 to Dart 2.0.

This change makes big_integer_arith_vm_test strong-mode compatible, and allows
dartdevc/dart2js to build and run big_integer tests where they can.
New issue 30170 filed to track DDC big integer handling.

BUG=
R=rnystrom@google.com

Review-Url: https://codereview.chromium.org/2978013002 .
This commit is contained in:
Janice Collins 2017-07-19 07:54:57 -07:00
parent 4f15ccd910
commit 70935d97c5
16 changed files with 48 additions and 1295 deletions

View file

@ -1,69 +0,0 @@
// Copyright (c) 2013, 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.
// Test [Function.apply] on user-defined classes that implement [noSuchMethod].
import "package:expect/expect.dart";
import 'dart:mirrors';
class F {
call([p1]) => "call";
noSuchMethod(Invocation invocation) => "NSM";
}
class G {
call() => '42';
noSuchMethod(Invocation invocation) => invocation;
}
class H {
call(required, {a}) => required + a;
}
main() {
Expect.equals('call', Function.apply(new F(), []));
Expect.equals('call', Function.apply(new F(), [1]));
Expect.equals('NSM', Function.apply(new F(), [1, 2]));
Expect.equals('NSM', Function.apply(new F(), [1, 2, 3]));
var symbol = const Symbol('a');
var requiredParameters = [1];
var optionalParameters = new Map()..[symbol] = 42;
Invocation i =
Function.apply(new G(), requiredParameters, optionalParameters);
Expect.equals(const Symbol('call'), i.memberName);
Expect.listEquals(requiredParameters, i.positionalArguments);
Expect.mapEquals(optionalParameters, i.namedArguments);
Expect.isTrue(i.isMethod);
Expect.isFalse(i.isGetter);
Expect.isFalse(i.isSetter);
Expect.isFalse(i.isAccessor);
// Check that changing the passed list and map for parameters does
// not affect [i].
requiredParameters[0] = 42;
optionalParameters[symbol] = 12;
Expect.listEquals([1], i.positionalArguments);
Expect.mapEquals(new Map()..[symbol] = 42, i.namedArguments);
// Check that using [i] for invocation yields the same [Invocation]
// object.
var mirror = reflect(new G());
Invocation other = mirror.delegate(i);
Expect.equals(i.memberName, other.memberName);
Expect.listEquals(i.positionalArguments, other.positionalArguments);
Expect.mapEquals(i.namedArguments, other.namedArguments);
Expect.equals(i.isMethod, other.isMethod);
Expect.equals(i.isGetter, other.isGetter);
Expect.equals(i.isSetter, other.isSetter);
Expect.equals(i.isAccessor, other.isAccessor);
// Test that [i] can be used to hit an existing method.
Expect.equals(43, new H().call(1, a: 42));
Expect.equals(43, Function.apply(new H(), [1], new Map()..[symbol] = 42));
mirror = reflect(new H());
Expect.equals(43, mirror.delegate(i));
Expect.equals(43, mirror.delegate(other));
}

View file

@ -1,447 +0,0 @@
// 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 Bigints with and without intrinsics.
// VMOptions=
// VMOptions=--no_intrinsify
// VMOptions=--no-background-compilation
// VMOptions=--optimization_counter_threshold=10 --no-background_compilation
library big_integer_test;
import "package:expect/expect.dart";
foo() => 1234567890123456789;
bar() => 12345678901234567890;
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);
}
testBigintAdd() {
// Bigint and Smi.
var a = 12345678901234567890;
var b = 2;
Expect.equals(12345678901234567892, a + b);
Expect.equals(12345678901234567892, b + a);
// Bigint and Bigint.
a = 10000000000000000001;
Expect.equals(20000000000000000002, a + a);
// Bigint and double.
a = 100000000000000000000.0;
b = 200000000000000000000;
Expect.isTrue((a + b) is double);
Expect.equals(300000000000000000000.0, a + b);
Expect.isTrue((b + a) is double);
Expect.equals(300000000000000000000.0, b + a);
}
testBigintSub() {
// Bigint and Smi.
var a = 12345678901234567890;
var b = 2;
Expect.equals(12345678901234567888, a - b);
Expect.equals(-12345678901234567888, b - a);
// Bigint and Bigint.
a = 10000000000000000001;
Expect.equals(20000000000000000002, a + a);
// Bigint and double.
a = 100000000000000000000.0;
b = 200000000000000000000;
Expect.isTrue((a + b) is double);
Expect.equals(-100000000000000000000.0, a - b);
Expect.isTrue((b + a) is double);
Expect.equals(100000000000000000000.0, b - a);
Expect.equals(-1, 0xF00000000 - 0xF00000001);
}
testBigintMul() {
// Bigint and Smi.
var a = 12345678901234567890;
var b = 10;
Expect.equals(123456789012345678900, a * b);
Expect.equals(123456789012345678900, b * a);
// Bigint and Bigint.
a = 12345678901234567890;
b = 10000000000000000;
Expect.equals(123456789012345678900000000000000000, a * b);
// Bigint and double.
a = 2.0;
b = 200000000000000000000;
Expect.isTrue((a * b) is double);
Expect.equals(400000000000000000000.0, a * b);
Expect.isTrue((b * a) is double);
Expect.equals(400000000000000000000.0, b * a);
}
testBigintTruncDiv() {
var a = 12345678901234567890;
var b = 10;
// Bigint and Smi.
Expect.equals(1234567890123456789, a ~/ b);
Expect.equals(0, b ~/ a);
Expect.equals(123456789, 123456789012345678 ~/ 1000000000);
// Bigint and Bigint.
a = 12345678901234567890;
b = 10000000000000000;
Expect.equals(1234, a ~/ b);
// Bigint and double.
a = 100000000000000000000.0;
b = 200000000000000000000;
Expect.equals(0, a ~/ b);
Expect.equals(2, b ~/ a);
}
testBigintDiv() {
// Bigint and Smi.
Expect.equals(1234567890123456789.1, 12345678901234567891 / 10);
Expect.equals(0.000000001234, 1234 / 1000000000000);
Expect.equals(12345678901234000000.0, 123456789012340000000 / 10);
// Bigint and Bigint.
var a = 12345670000000000000;
var b = 10000000000000000;
Expect.equals(1234.567, a / b);
// Bigint and double.
a = 400000000000000000000.0;
b = 200000000000000000000;
Expect.equals(2.0, a / b);
Expect.equals(0.5, b / a);
}
testBigintModulo() {
// Bigint and Smi.
var a = 1000000000005;
var b = 10;
Expect.equals(5, a % b);
Expect.equals(10, b % a);
// Bigint & Bigint
a = 10000000000000000001;
b = 10000000000000000000;
Expect.equals(1, a % b);
Expect.equals(10000000000000000000, b % a);
// Bigint & double.
a = 10000000100000000.0;
b = 10000000000000000;
Expect.equals(100000000.0, a % b);
Expect.equals(10000000000000000.0, b % a);
// Transitioning from Mint to Bigint.
var iStart = 4611686018427387900;
var prevX = -23 % iStart;
for (int i = iStart + 1; i < iStart + 10; i++) {
var x = -23 % i;
Expect.equals(1, x - prevX);
Expect.isTrue(x > 0);
prevX = x;
}
}
testBigintModPow() {
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));
x = 12345678901234567890;
e = 10000000000000000001;
m = 19;
Expect.equals(2, x.modPow(e, m));
x = 12345678901234567890;
e = 19;
m = 10000000000000000001;
Expect.equals(3239137215315834625, x.modPow(e, m));
x = 19;
e = 12345678901234567890;
m = 10000000000000000001;
Expect.equals(4544207837373941034, x.modPow(e, m));
x = 19;
e = 10000000000000000001;
m = 12345678901234567890;
Expect.equals(11135411705397624859, x.modPow(e, m));
x = 10000000000000000001;
e = 19;
m = 12345678901234567890;
Expect.equals(2034013733189773841, x.modPow(e, m));
x = 10000000000000000001;
e = 12345678901234567890;
m = 19;
Expect.equals(1, x.modPow(e, m));
x = 12345678901234567890;
e = 19;
m = 10000000000000000001;
Expect.equals(3239137215315834625, x.modPow(e, m));
x = 12345678901234567890;
e = 10000000000000000001;
m = 19;
Expect.equals(2, x.modPow(e, m));
x = 123456789012345678901234567890;
e = 123456789012345678901234567891;
m = 123456789012345678901234567899;
Expect.equals(116401406051033429924651549616, x.modPow(e, m));
x = 123456789012345678901234567890;
e = 123456789012345678901234567899;
m = 123456789012345678901234567891;
Expect.equals(123456789012345678901234567890, x.modPow(e, m));
x = 123456789012345678901234567899;
e = 123456789012345678901234567890;
m = 123456789012345678901234567891;
Expect.equals(35088523091000351053091545070, x.modPow(e, m));
x = 123456789012345678901234567899;
e = 123456789012345678901234567891;
m = 123456789012345678901234567890;
Expect.equals(18310047270234132455316941949, x.modPow(e, m));
x = 123456789012345678901234567891;
e = 123456789012345678901234567899;
m = 123456789012345678901234567890;
Expect.equals(1, x.modPow(e, m));
x = 123456789012345678901234567891;
e = 123456789012345678901234567890;
m = 123456789012345678901234567899;
Expect.equals(40128068573873018143207285483, x.modPow(e, m));
}
testBigintModInverse() {
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.
x = 12345678901234567890;
m = 19;
Expect.equals(3, x.modInverse(m));
x = 12345678901234567890;
m = 10000000000000000001;
Expect.equals(9736746307686209582, x.modInverse(m));
x = 19;
m = 10000000000000000001;
Expect.equals(6315789473684210527, x.modInverse(m));
x = 19;
m = 12345678901234567890;
Expect.equals(10396361179987004539, x.modInverse(m));
x = 10000000000000000001;
m = 12345678901234567890;
Expect.equals(325004555487045911, x.modInverse(m));
x = 10000000000000000001;
m = 19;
Expect.equals(7, x.modInverse(m));
x = 12345678901234567890;
m = 10000000000000000001;
Expect.equals(9736746307686209582, x.modInverse(m));
x = 12345678901234567890;
m = 19;
Expect.equals(3, x.modInverse(m));
x = 123456789012345678901234567890;
m = 123456789012345678901234567899;
Expect.throws(() => x.modInverse(m), (e) => e is Exception); // Not coprime.
x = 123456789012345678901234567890;
m = 123456789012345678901234567891;
Expect.equals(123456789012345678901234567890, x.modInverse(m));
x = 123456789012345678901234567899;
m = 123456789012345678901234567891;
Expect.equals(77160493132716049313271604932, x.modInverse(m));
x = 123456789012345678901234567899;
m = 123456789012345678901234567890;
Expect.throws(() => x.modInverse(m), (e) => e is Exception); // Not coprime.
x = 123456789012345678901234567891;
m = 123456789012345678901234567890;
Expect.equals(1, x.modInverse(m));
x = 123456789012345678901234567891;
m = 123456789012345678901234567899;
Expect.equals(46296295879629629587962962962, x.modInverse(m));
}
testBigintGcd() {
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 = 0;
m = 123456789012345678901234567890;
Expect.equals(m, x.gcd(m));
x = 123456789012345678901234567890;
m = 0;
Expect.equals(x, x.gcd(m));
x = 0;
m = -123456789012345678901234567890;
Expect.equals(-m, x.gcd(m));
x = -123456789012345678901234567890;
m = 0;
Expect.equals(-x, 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));
x = 12345678901234567890;
m = 19;
Expect.equals(1, x.gcd(m));
x = 12345678901234567890;
m = 10000000000000000001;
Expect.equals(1, x.gcd(m));
x = 19;
m = 10000000000000000001;
Expect.equals(1, x.gcd(m));
x = 19;
m = 12345678901234567890;
Expect.equals(1, x.gcd(m));
x = 10000000000000000001;
m = 12345678901234567890;
Expect.equals(1, x.gcd(m));
x = 10000000000000000001;
m = 19;
Expect.equals(1, x.gcd(m));
x = 12345678901234567890;
m = 10000000000000000001;
Expect.equals(1, x.gcd(m));
x = 12345678901234567890;
m = 19;
Expect.equals(1, x.gcd(m));
x = 123456789012345678901234567890;
m = 123456789012345678901234567899;
Expect.equals(9, x.gcd(m));
x = 123456789012345678901234567890;
m = 123456789012345678901234567891;
Expect.equals(1, x.gcd(m));
x = 123456789012345678901234567899;
m = 123456789012345678901234567891;
Expect.equals(1, x.gcd(m));
x = 123456789012345678901234567899;
m = 123456789012345678901234567890;
Expect.equals(9, x.gcd(m));
x = 123456789012345678901234567891;
m = 123456789012345678901234567890;
Expect.equals(1, x.gcd(m));
x = 123456789012345678901234567891;
m = 123456789012345678901234567899;
Expect.equals(1, x.gcd(m));
}
testBigintNegate() {
var a = 0xF000000000000000F;
var b = ~a; // negate.
Expect.equals(-0xF0000000000000010, b);
Expect.equals(0, a & b);
Expect.equals(-1, a | b);
}
testShiftAmount() {
Expect.equals(0, 12 >> 111111111111111111111111111111);
Expect.equals(-1, -12 >> 111111111111111111111111111111);
bool exceptionCaught = false;
try {
var a = 1 << 1111111111111111111111111111;
} on OutOfMemoryError catch (e) {
exceptionCaught = true;
}
Expect.equals(true, exceptionCaught);
}
main() {
for (int i = 0; i < 10; i++) {
Expect.equals(1234567890123456789, foo());
Expect.equals(12345678901234567890, bar());
testSmiOverflow(); // //# overflow: ok
testBigintAdd(); // //# add: ok
testBigintSub(); // //# sub: ok
testBigintMul(); // //# mul: ok
testBigintTruncDiv(); // //# trunDiv: ok
testBigintDiv(); // //# div: ok
testBigintModulo(); // //# mod: ok
testBigintModPow(); // //# modPow: ok
testBigintModInverse(); // //# modInv: ok
testBigintGcd(); // //# gcd: ok
testBigintNegate(); // //# negate: ok
testShiftAmount(); // //# shift: ok
Expect.equals(12345678901234567890, (12345678901234567890).abs());
Expect.equals(12345678901234567890, (-12345678901234567890).abs());
var a = 10000000000000000000;
var b = 10000000000000000001;
Expect.equals(false, a.hashCode == b.hashCode);
Expect.equals(true, a.hashCode == (b - 1).hashCode);
}
}

View file

@ -47,9 +47,6 @@ int_modulo_arith_test/modPow: RuntimeError # No bigints.
list_unmodifiable_test: Pass, RuntimeError # Issue 28712
symbol_reserved_word_test/05: Crash # bug 20191
[ $compiler == dart2js && $fast_startup ]
apply3_test: Fail # mirrors not supported
[ ($compiler == none || $compiler == precompiler || $compiler == app_jit) && $runtime != dartium && $runtime != drt ]
symbol_test/02: MissingCompileTimeError # bug 11669
symbol_test/03: MissingCompileTimeError # bug 11669
@ -168,9 +165,7 @@ int_parse_radix_test/*: Pass, Slow
big_integer_parsed_mul_div_vm_test: Pass, Slow
[ $compiler == precompiler ]
apply3_test: SkipByDesign # Imports dart:mirrors
regexp/stack-overflow_test: RuntimeError, OK # Smaller limit with irregex interpreter
big_integer_huge_mul_vm_test: Pass, Timeout # --no_intrinsify
big_integer_parsed_mul_div_vm_test: Pass, Timeout # --no_intrinsify
int_parse_radix_test: Pass, Timeout # --no_intrinsify
@ -185,7 +180,6 @@ regexp/stack-overflow_test: RuntimeError, OK # Smaller limit with irregex interp
[ $hot_reload || $hot_reload_rollback ]
big_integer_parsed_mul_div_vm_test: Pass, Slow # Slow.
big_integer_huge_mul_vm_test: Pass, Slow # Slow
[ $compiler == dart2js && $dart2js_with_kernel ]
error_stack_trace1_test: Pass # Issue 27394
@ -258,9 +252,6 @@ from_environment_const_type_undefined_test/08: MissingCompileTimeError
[ $runtime == flutter ]
# No support for mirrors
apply3_test: CompileTimeError
# Possible bugs
format_exception_test: RuntimeError # Flutter Issue 9111
string_from_environment_test: Fail # Flutter Issue 9111

View file

@ -34,12 +34,12 @@ testBigintAdd() {
a = 10000000000000000001;
Expect.equals(20000000000000000002, a + a);
// Bigint and double.
a = 100000000000000000000.0;
b = 200000000000000000000;
Expect.isTrue((a + b) is double);
Expect.equals(300000000000000000000.0, a + b);
Expect.isTrue((b + a) is double);
Expect.equals(300000000000000000000.0, b + a);
var c = 100000000000000000000.0;
Expect.isTrue((c + b) is double);
Expect.equals(300000000000000000000.0, b + c);
Expect.isTrue((b + c) is double);
Expect.equals(300000000000000000000.0, c + b);
}
testBigintSub() {
@ -52,12 +52,12 @@ testBigintSub() {
a = 10000000000000000001;
Expect.equals(20000000000000000002, a + a);
// Bigint and double.
a = 100000000000000000000.0;
b = 200000000000000000000;
Expect.isTrue((a + b) is double);
Expect.equals(-100000000000000000000.0, a - b);
Expect.isTrue((b + a) is double);
Expect.equals(100000000000000000000.0, b - a);
var c = 100000000000000000000.0;
Expect.isTrue((c + b) is double);
Expect.equals(-100000000000000000000.0, c - b);
Expect.isTrue((b + c) is double);
Expect.equals(100000000000000000000.0, b - c);
Expect.equals(-1, 0xF00000000 - 0xF00000001);
}
@ -72,12 +72,12 @@ testBigintMul() {
b = 10000000000000000;
Expect.equals(123456789012345678900000000000000000, a * b);
// Bigint and double.
a = 2.0;
b = 200000000000000000000;
Expect.isTrue((a * b) is double);
Expect.equals(400000000000000000000.0, a * b);
Expect.isTrue((b * a) is double);
Expect.equals(400000000000000000000.0, b * a);
var c = 2.0;
Expect.isTrue((c * b) is double);
Expect.equals(400000000000000000000.0, c * b);
Expect.isTrue((b * c) is double);
Expect.equals(400000000000000000000.0, b * c);
}
testBigintTruncDiv() {
@ -92,10 +92,10 @@ testBigintTruncDiv() {
b = 10000000000000000;
Expect.equals(1234, a ~/ b);
// Bigint and double.
a = 100000000000000000000.0;
b = 200000000000000000000;
Expect.equals(0, a ~/ b);
Expect.equals(2, b ~/ a);
var c = 100000000000000000000.0;
Expect.equals(0, c ~/ b);
Expect.equals(2, b ~/ c);
}
testBigintDiv() {
@ -108,10 +108,10 @@ testBigintDiv() {
var b = 10000000000000000;
Expect.equals(1234.567, a / b);
// Bigint and double.
a = 400000000000000000000.0;
b = 200000000000000000000;
Expect.equals(2.0, a / b);
Expect.equals(0.5, b / a);
var c = 400000000000000000000.0;
Expect.equals(2.0, c / b);
Expect.equals(0.5, b / c);
}
testBigintModulo() {
@ -126,10 +126,10 @@ testBigintModulo() {
Expect.equals(1, a % b);
Expect.equals(10000000000000000000, b % a);
// Bigint & double.
a = 10000000100000000.0;
b = 10000000000000000;
Expect.equals(100000000.0, a % b);
Expect.equals(10000000000000000.0, b % a);
var c = 10000000100000000.0;
Expect.equals(100000000.0, c % b);
Expect.equals(10000000000000000.0, b % c);
// Transitioning from Mint to Bigint.
var iStart = 4611686018427387900;
var prevX = -23 % iStart;

View file

@ -1,3 +1,27 @@
# Copyright (c) 2017, 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.
[ $compiler == dart2js && $fast_startup ]
apply3_test: Fail # mirrors not supported
[ $compiler == precompiler ]
apply3_test: SkipByDesign
big_integer_huge_mul_vm_test: Pass, Timeout # --no_intrinsify
[ $compiler == dartdevc && $runtime != none ]
apply2_test: RuntimeError # Issue 29921
apply3_test: RuntimeError # Issue 29921
big_integer_arith_vm_test: RuntimeError # Issue 30170
big_integer_parsed_arith_vm_test: RuntimeError # Issue 29921
[ $compiler == dart2js && $runtime != none ]
big_integer_arith_vm_test: RuntimeError # Issue 10245
big_integer_parsed_arith_vm_test: RuntimeError # Issue 10245
[ $runtime == flutter ]
apply3_test: CompileTimeError # mirrors not supported
[ $hot_reload || $hot_reload_rollback ]
big_integer_huge_mul_vm_test: Pass, Slow # Slow

View file

@ -1,96 +0,0 @@
// Copyright (c) 2012, 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.
import "package:expect/expect.dart";
apply(Function function, List positional, Map<Symbol, dynamic> named) {
return Function.apply(function, positional, named);
}
void throwsNSME(function, positional, named) {
Expect.throws(
() => apply(function, positional, named), (e) => e is NoSuchMethodError);
}
main() {
var c1 = () => 'c1';
var c2 = (a) => 'c2 $a';
var c3 = ([a = 1]) => 'c3 $a';
var c4 = ({a: 1}) => 'c4 $a';
var c5 = ({a: 1, b: 2}) => 'c5 $a $b';
var c6 = ({b: 1, a: 2}) => 'c6 $a $b';
var c7 = (x, {b: 1, a: 2}) => 'c7 $x $a $b';
var c8 = (x, y, [a = 2, b = 3]) => 'c8 $x $y $a $b';
Expect.equals('c1', apply(c1, null, null));
Expect.equals('c1', apply(c1, [], null));
Expect.equals('c1', apply(c1, [], {}));
Expect.equals('c1', apply(c1, null, {}));
throwsNSME(c1, [1], null);
throwsNSME(c1, [1], {#a: 2});
throwsNSME(c1, null, {#a: 2});
Expect.equals('c2 1', apply(c2, [1], null));
Expect.equals('c2 1', apply(c2, [1], {}));
throwsNSME(c2, null, null);
throwsNSME(c2, [], null);
throwsNSME(c2, null, {});
throwsNSME(c2, null, {#a: 1});
throwsNSME(c2, [2], {#a: 1});
Expect.equals('c3 1', apply(c3, null, null));
Expect.equals('c3 1', apply(c3, [], null));
Expect.equals('c3 2', apply(c3, [2], {}));
throwsNSME(c3, [1, 2], null);
throwsNSME(c3, null, {#a: 1});
Expect.equals('c4 1', apply(c4, [], null));
Expect.equals('c4 2', apply(c4, [], {#a: 2}));
Expect.equals('c4 1', apply(c4, null, null));
Expect.equals('c4 1', apply(c4, [], {}));
throwsNSME(c4, [1], {#a: 1});
throwsNSME(c4, [1], {});
throwsNSME(c4, [], {#a: 1, #b: 2});
Expect.equals('c5 1 2', apply(c5, [], null));
Expect.equals('c5 3 2', apply(c5, [], {#a: 3}));
Expect.equals('c5 1 2', apply(c5, null, null));
Expect.equals('c5 1 2', apply(c5, [], {}));
Expect.equals('c5 3 4', apply(c5, [], {#a: 3, #b: 4}));
Expect.equals('c5 4 3', apply(c5, [], {#b: 3, #a: 4}));
Expect.equals('c5 1 3', apply(c5, [], {#b: 3}));
throwsNSME(c5, [1], {#a: 1});
throwsNSME(c5, [1], {});
throwsNSME(c5, [], {#a: 1, #b: 2, #c: 3});
Expect.equals('c6 2 1', apply(c6, [], null));
Expect.equals('c6 3 1', apply(c6, [], {#a: 3}));
Expect.equals('c6 2 1', apply(c6, null, null));
Expect.equals('c6 2 1', apply(c6, [], {}));
Expect.equals('c6 3 4', apply(c6, [], {#a: 3, #b: 4}));
Expect.equals('c6 4 3', apply(c6, [], {#b: 3, #a: 4}));
Expect.equals('c6 2 3', apply(c6, [], {#b: 3}));
throwsNSME(c6, [1], {#a: 1});
throwsNSME(c6, [1], {});
throwsNSME(c6, [], {#a: 1, #b: 2, #c: 3});
Expect.equals('c7 7 2 1', apply(c7, [7], null));
Expect.equals('c7 7 3 1', apply(c7, [7], {#a: 3}));
Expect.equals('c7 7 2 1', apply(c7, [7], {}));
Expect.equals('c7 7 3 4', apply(c7, [7], {#a: 3, #b: 4}));
Expect.equals('c7 7 4 3', apply(c7, [7], {#b: 3, #a: 4}));
Expect.equals('c7 7 2 3', apply(c7, [7], {#b: 3}));
throwsNSME(c7, [], {#a: 1});
throwsNSME(c7, [], {});
throwsNSME(c7, [7], {#a: 1, #b: 2, #c: 3});
Expect.equals('c8 7 8 2 3', apply(c8, [7, 8], null));
Expect.equals('c8 7 8 2 3', apply(c8, [7, 8], {}));
Expect.equals('c8 7 8 3 3', apply(c8, [7, 8, 3], null));
Expect.equals('c8 7 8 3 4', apply(c8, [7, 8, 3, 4], null));
throwsNSME(c8, [], null);
throwsNSME(c8, [], {});
throwsNSME(c8, [1], null);
throwsNSME(c8, [7, 8, 9, 10, 11], null);
}

View file

@ -1,20 +0,0 @@
// Copyright (c) 2015, 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.
import "package:expect/expect.dart";
// Testing Function.apply calls work correctly for arities that are not
// otherwise present in the program (and thus might not have stubs
// generated).
class A {
foo(x, [y, z, a, b, c, d = 99, e, f, g, h, i, j]) => "$x $d";
}
main() {
var a = new A();
var clos = a.foo;
Expect.equals(Function.apply(clos, ["well"]), "well 99");
Expect.equals(Function.apply(clos, ["well", 0, 2, 4, 3, 6, 9, 10]), "well 9");
}

View file

@ -1,25 +0,0 @@
// 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 Bigints with and without intrinsics.
// VMOptions=
// VMOptions=--no_intrinsify
library big_integer_test;
import "package:expect/expect.dart";
testBigintHugeMul() {
var bits = 65536;
var a = 1 << bits;
var a1 = a - 1; // all 1's
var p1 = a1 * a1;
var p2 = a * a - a - a + 1;
// Use isTrue instead of equals to avoid trying to print such big numbers.
Expect.isTrue(p1 == p2, 'products do not match');
}
main() {
testBigintHugeMul();
}

View file

@ -1,601 +0,0 @@
// 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 Bigints with and without intrinsics.
// VMOptions=
// VMOptions=--no_intrinsify
library big_integer_test;
import "package:expect/expect.dart";
addSubParsed(String a, String b, String sum) {
int int_a = int.parse(a);
int int_b = int.parse(b);
int int_sum = int.parse(sum);
int computed_sum = int_a + int_b;
Expect.equals(int_sum, computed_sum);
String str_sum = computed_sum >= 0
? "0x${computed_sum.toRadixString(16)}"
: "-0x${(-computed_sum).toRadixString(16)}";
Expect.equals(sum.toLowerCase(), str_sum);
int computed_difference1 = int_sum - int_a;
Expect.equals(int_b, computed_difference1);
String str_difference1 = computed_difference1 >= 0
? "0x${computed_difference1.toRadixString(16)}"
: "-0x${(-computed_difference1).toRadixString(16)}";
Expect.equals(b.toLowerCase(), str_difference1);
int computed_difference2 = int_sum - int_b;
Expect.equals(int_a, computed_difference2);
String str_difference2 = computed_difference2 >= 0
? "0x${computed_difference2.toRadixString(16)}"
: "-0x${(-computed_difference2).toRadixString(16)}";
Expect.equals(a.toLowerCase(), str_difference2);
}
testBigintAddSub() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
addSubParsed(zero, zero, zero);
addSubParsed(zero, one, one);
addSubParsed(one, zero, one);
addSubParsed(one, one, "0x2");
addSubParsed(minus_one, minus_one, "-0x2");
addSubParsed("0x123", zero, "0x123");
addSubParsed(zero, "0x123", "0x123");
addSubParsed("0x123", one, "0x124");
addSubParsed(one, "0x123", "0x124");
addSubParsed(
"0xFFFFFFF",
one, // 28 bit overflow.
"0x10000000");
addSubParsed(
"0xFFFFFFFF",
one, // 32 bit overflow.
"0x100000000");
addSubParsed(
"0xFFFFFFFFFFFFFF",
one, // 56 bit overflow.
"0x100000000000000");
addSubParsed(
"0xFFFFFFFFFFFFFFFF",
one, // 64 bit overflow.
"0x10000000000000000");
addSubParsed(
"0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", // 128 bit.
one,
"0x100000000000000000000000000000000");
addSubParsed("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", one,
"0x10000000000000000000000000000000000000000000");
addSubParsed(
"0x8000000", // 28 bit overflow.
"0x8000000",
"0x10000000");
addSubParsed(
"0x80000000", // 32 bit overflow.
"0x80000000",
"0x100000000");
addSubParsed(
"0x80000000000000", // 56 bit overflow.
"0x80000000000000",
"0x100000000000000");
addSubParsed(
"0x8000000000000000", // 64 bit overflow.
"0x8000000000000000",
"0x10000000000000000");
addSubParsed(
"0x80000000000000000000000000000000", // 128 bit.
"0x80000000000000000000000000000000",
"0x100000000000000000000000000000000");
addSubParsed(
"0x8000000000000000000000000000000000000000000",
"0x8000000000000000000000000000000000000000000",
"0x10000000000000000000000000000000000000000000");
{
String a = "0x123456789ABCDEF01234567890ABCDEF0123456789ABCDEF0";
String sum1 = "0x123456789ABCDEF01234567890ABCDEF0123456789ABCDEF1";
String times2 = "0x2468ACF13579BDE02468ACF121579BDE02468ACF13579BDE0";
addSubParsed(a, zero, a);
addSubParsed(a, one, sum1);
addSubParsed(a, a, times2);
}
addSubParsed("-0x123", minus_one, "-0x124");
addSubParsed(minus_one, "-0x123", "-0x124");
addSubParsed(
"-0xFFFFFFF",
minus_one, // 28 bit overflow.
"-0x10000000");
addSubParsed(
"-0xFFFFFFFF",
minus_one, // 32 bit overflow.
"-0x100000000");
addSubParsed(
"-0xFFFFFFFFFFFFFF",
minus_one, // 56 bit overflow.
"-0x100000000000000");
addSubParsed(
"-0xFFFFFFFFFFFFFFFF",
minus_one, // 64 bit overflow.
"-0x10000000000000000");
addSubParsed(
"-0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", // 128 bit.
minus_one,
"-0x100000000000000000000000000000000");
addSubParsed("-0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", minus_one,
"-0x10000000000000000000000000000000000000000000");
addSubParsed(
"-0x8000000", // 28 bit overflow.
"-0x8000000",
"-0x10000000");
addSubParsed(
"-0x80000000", // 32 bit overflow.
"-0x80000000",
"-0x100000000");
addSubParsed(
"-0x80000000000000", // 56 bit overflow.
"-0x80000000000000",
"-0x100000000000000");
addSubParsed(
"-0x8000000000000000", // 64 bit overflow.
"-0x8000000000000000",
"-0x10000000000000000");
addSubParsed(
"-0x80000000000000000000000000000000", // 128 bit.
"-0x80000000000000000000000000000000",
"-0x100000000000000000000000000000000");
addSubParsed(
"-0x8000000000000000000000000000000000000000000",
"-0x8000000000000000000000000000000000000000000",
"-0x10000000000000000000000000000000000000000000");
{
String a = "-0x123456789ABCDEF01234567890ABCDEF0123456789ABCDEF0";
String sum1 = "-0x123456789ABCDEF01234567890ABCDEF0123456789ABCDEF1";
String times2 = "-0x2468ACF13579BDE02468ACF121579BDE02468ACF13579BDE0";
addSubParsed(a, zero, a);
addSubParsed(a, minus_one, sum1);
addSubParsed(a, a, times2);
}
addSubParsed("0x10000000000000000000000000000000000000000000", "0xFFFF",
"0x1000000000000000000000000000000000000000FFFF");
addSubParsed("0x10000000000000000000000000000000000000000000",
"0xFFFF00000000", "0x10000000000000000000000000000000FFFF00000000");
addSubParsed("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "0x100000000",
"0x1000000000000000000000000000000000000FFFFFFFF");
addSubParsed(
"0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"0x10000000000000000000",
"0x10000000000000000000000000FFFFFFFFFFFFFFFFFFF");
addSubParsed("0xB", "-0x7", "0x4");
addSubParsed("-0xB", "-0x7", "-0x12");
addSubParsed("0xB", "0x7", "0x12");
addSubParsed("-0xB", "0x7", "-0x4");
addSubParsed("-0x7", "0xB", "0x4");
addSubParsed("-0x7", "-0xB", "-0x12");
addSubParsed("0x7", "0xB", "0x12");
addSubParsed("0x7", "-0xB", "-0x4");
}
shiftLeftParsed(String a, int amount, String result) {
int int_a = int.parse(a);
int int_result = int.parse(result);
int shifted = int_a << amount;
Expect.equals(int_result, shifted);
String str_shifted = shifted >= 0
? "0x${shifted.toRadixString(16)}"
: "-0x${(-shifted).toRadixString(16)}";
Expect.equals(result.toLowerCase(), str_shifted);
int back_shifted = shifted >> amount;
Expect.equals(int_a, back_shifted);
String str_back_shifted = back_shifted >= 0
? "0x${back_shifted.toRadixString(16)}"
: "-0x${(-back_shifted).toRadixString(16)}";
Expect.equals(a.toLowerCase(), str_back_shifted);
}
testBigintLeftShift() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
shiftLeftParsed(zero, 0, zero);
shiftLeftParsed(one, 0, one);
shiftLeftParsed("0x1234", 0, "0x1234");
shiftLeftParsed(zero, 100000, zero);
shiftLeftParsed(one, 1, "0x2");
shiftLeftParsed(one, 28, "0x10000000");
shiftLeftParsed(one, 32, "0x100000000");
shiftLeftParsed(one, 64, "0x10000000000000000");
shiftLeftParsed("0x5", 28, "0x50000000");
shiftLeftParsed("0x5", 32, "0x500000000");
shiftLeftParsed("0x5", 56, "0x500000000000000");
shiftLeftParsed("0x5", 64, "0x50000000000000000");
shiftLeftParsed("0x5", 128, "0x500000000000000000000000000000000");
shiftLeftParsed("0x5", 27, "0x28000000");
shiftLeftParsed("0x5", 31, "0x280000000");
shiftLeftParsed("0x5", 55, "0x280000000000000");
shiftLeftParsed("0x5", 63, "0x28000000000000000");
shiftLeftParsed("0x5", 127, "0x280000000000000000000000000000000");
shiftLeftParsed("0x8000001", 1, "0x10000002");
shiftLeftParsed("0x80000001", 1, "0x100000002");
shiftLeftParsed("0x8000000000000001", 1, "0x10000000000000002");
shiftLeftParsed("0x8000001", 29, "0x100000020000000");
shiftLeftParsed("0x80000001", 33, "0x10000000200000000");
shiftLeftParsed(
"0x8000000000000001", 65, "0x100000000000000020000000000000000");
shiftLeftParsed(minus_one, 0, minus_one);
shiftLeftParsed("-0x1234", 0, "-0x1234");
shiftLeftParsed(minus_one, 1, "-0x2");
shiftLeftParsed(minus_one, 28, "-0x10000000");
shiftLeftParsed(minus_one, 32, "-0x100000000");
shiftLeftParsed(minus_one, 64, "-0x10000000000000000");
shiftLeftParsed("-0x5", 28, "-0x50000000");
shiftLeftParsed("-0x5", 32, "-0x500000000");
shiftLeftParsed("-0x5", 64, "-0x50000000000000000");
shiftLeftParsed("-0x5", 27, "-0x28000000");
shiftLeftParsed("-0x5", 31, "-0x280000000");
shiftLeftParsed("-0x5", 63, "-0x28000000000000000");
shiftLeftParsed("-0x8000001", 1, "-0x10000002");
shiftLeftParsed("-0x80000001", 1, "-0x100000002");
shiftLeftParsed("-0x8000000000000001", 1, "-0x10000000000000002");
shiftLeftParsed("-0x8000001", 29, "-0x100000020000000");
shiftLeftParsed("-0x80000001", 33, "-0x10000000200000000");
shiftLeftParsed(
"-0x8000000000000001", 65, "-0x100000000000000020000000000000000");
}
shiftRightParsed(String a, int amount, String result) {
int int_a = int.parse(a);
int int_result = int.parse(result);
int shifted = int_a >> amount;
Expect.equals(int_result, shifted);
String str_shifted = shifted >= 0
? "0x${shifted.toRadixString(16)}"
: "-0x${(-shifted).toRadixString(16)}";
Expect.equals(result.toLowerCase(), str_shifted);
}
testBigintRightShift() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
shiftRightParsed(one, 1, zero);
shiftRightParsed(minus_one, 1, minus_one);
shiftRightParsed("-0x2", 1, minus_one);
shiftRightParsed("0x12345678", 29, zero);
shiftRightParsed("-0x12345678", 29, minus_one);
shiftRightParsed("-0x12345678", 100, minus_one);
shiftRightParsed("0x5", 1, "0x2");
shiftRightParsed("0x5", 2, "0x1");
shiftRightParsed("-0x5", 1, "-0x3");
shiftRightParsed("-0x5", 2, "-0x2");
shiftRightParsed("0x10000001", 28, one);
shiftRightParsed("0x100000001", 32, one);
shiftRightParsed("0x10000000000000001", 64, one);
shiftRightParsed("-0x10000001", 28, "-0x2");
shiftRightParsed("-0x100000001", 32, "-0x2");
shiftRightParsed("-0x10000000000000001", 64, "-0x2");
shiftRightParsed("0x30000000", 29, one);
shiftRightParsed("0x300000000", 33, one);
shiftRightParsed("0x30000000000000000", 65, one);
shiftRightParsed("-0x30000000", 29, "-0x2");
shiftRightParsed("-0x300000000", 33, "-0x2");
shiftRightParsed("-0x30000000000000000", 65, "-0x2");
}
bitAndParsed(String a, String b, String result) {
int int_a = int.parse(a);
int int_b = int.parse(b);
int int_result = int.parse(result);
int anded = int_a & int_b;
Expect.equals(int_result, anded);
String str_anded = anded >= 0
? "0x${anded.toRadixString(16)}"
: "-0x${(-anded).toRadixString(16)}";
Expect.equals(result.toLowerCase(), str_anded);
int anded2 = int_b & int_a;
Expect.equals(int_result, anded2);
String str_anded2 = anded2 >= 0
? "0x${anded2.toRadixString(16)}"
: "-0x${(-anded2).toRadixString(16)}";
Expect.equals(result.toLowerCase(), str_anded2);
}
testBigintBitAnd() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
bitAndParsed(one, zero, zero);
bitAndParsed(one, one, one);
bitAndParsed(minus_one, zero, zero);
bitAndParsed(minus_one, one, one);
bitAndParsed(minus_one, minus_one, minus_one);
bitAndParsed("0x5", "0x3", one);
bitAndParsed("0x5", minus_one, "0x5");
bitAndParsed("0x50000000", one, zero);
bitAndParsed("0x50000000", minus_one, "0x50000000");
bitAndParsed("0x500000000", one, zero);
bitAndParsed("0x500000000", minus_one, "0x500000000");
bitAndParsed("0x50000000000000000", one, zero);
bitAndParsed("0x50000000000000000", minus_one, "0x50000000000000000");
bitAndParsed("-0x50000000", "-0x50000000", "-0x50000000");
bitAndParsed("-0x500000000", "-0x500000000", "-0x500000000");
bitAndParsed(
"-0x50000000000000000", "-0x50000000000000000", "-0x50000000000000000");
bitAndParsed("0x1234567890ABCDEF012345678", "0x876543210FEDCBA0987654321",
"0x224422000A9C9A0002244220");
bitAndParsed("-0x1234567890ABCDEF012345678", "-0x876543210FEDCBA0987654321",
"-0x977557799FEFCFEF997755778");
bitAndParsed("0x1234567890ABCDEF012345678", "-0x876543210FEDCBA0987654321",
"0x101014589002044F010101458");
bitAndParsed(
"0x1234567890ABCDEF012345678FFFFFFFFFFFFFFFFFFFFFFFFF",
"-0x876543210FEDCBA0987654321",
"0x1234567890ABCDEF012345678789ABCDEF012345F6789ABCDF");
bitAndParsed("0x12345678", "0xFFFFFFF", "0x2345678");
bitAndParsed("0x123456789", "0xFFFFFFFF", "0x23456789");
bitAndParsed("-0x10000000", "0xFFFFFFF", "0x0");
bitAndParsed("-0x100000000", "0xFFFFFFFF", "0x0");
bitAndParsed("-0x10000001", "0xFFFFFFF", "0xFFFFFFF");
bitAndParsed("-0x100000001", "0xFFFFFFFF", "0xFFFFFFFF");
bitAndParsed("-0x10000001", "0x3FFFFFFF", "0x2FFFFFFF");
bitAndParsed("-0x100000001", "0x3FFFFFFFF", "0x2FFFFFFFF");
bitAndParsed(
"-0x10000000000000001", "0x3FFFFFFFFFFFFFFFF", "0x2FFFFFFFFFFFFFFFF");
bitAndParsed("-0x100000000000000", "0xFFFFFFFFFFFFFF", "0x0");
bitAndParsed("-0x10000000000000000", "0xFFFFFFFFFFFFFFFF", "0x0");
bitAndParsed("-0x300000000000000", "0xFFFFFFFFFFFFFFF", "0xD00000000000000");
bitAndParsed(
"-0x30000000000000000", "0xFFFFFFFFFFFFFFFFF", "0xD0000000000000000");
bitAndParsed("-0x10000000", "-0x10000000", "-0x10000000");
bitAndParsed("-0x100000000", "-0x100000000", "-0x100000000");
bitAndParsed(
"-0x100000000000000", "-0x100000000000000", "-0x100000000000000");
bitAndParsed(
"-0x10000000000000000", "-0x10000000000000000", "-0x10000000000000000");
bitAndParsed("-0x3", "-0x2", "-0x4");
bitAndParsed("-0x10000000", "-0x10000001", "-0x20000000");
bitAndParsed("-0x100000000", "-0x100000001", "-0x200000000");
bitAndParsed(
"-0x100000000000000", "-0x100000000000001", "-0x200000000000000");
bitAndParsed(
"-0x10000000000000000", "-0x10000000000000001", "-0x20000000000000000");
bitAndParsed(
"0x123456789ABCDEF01234567890",
"0x3FFFFFFF", // Max Smi for 32 bits.
"0x34567890");
bitAndParsed(
"0x123456789ABCDEF01274567890",
"0x3FFFFFFF", // Max Smi for 32 bits.
"0x34567890");
bitAndParsed(
"0x123456789ABCDEF01234567890",
"0x40000000", // Max Smi for 32 bits + 1.
"0x0");
bitAndParsed(
"0x123456789ABCDEF01274567890",
"0x40000000", // Max Smi for 32 bits + 1.
"0x40000000");
bitAndParsed(
"0x123456789ABCDEF01234567890",
"0x3FFFFFFFFFFFFFFF", // Max Smi for 64 bits.
"0x3CDEF01234567890");
bitAndParsed(
"0x123456789ACCDEF01234567890",
"0x4000000000000000", // Max Smi for 64 bits + 1.
"0x4000000000000000");
bitAndParsed(
"0x123456789ABCDEF01234567890",
"0x4000000000000000", // Max Smi for 64 bits + 1.
"0x0");
}
bitOrParsed(String a, String b, String result) {
int int_a = int.parse(a);
int int_b = int.parse(b);
int int_result = int.parse(result);
int ored = int_a | int_b;
Expect.equals(int_result, ored);
String str_ored = ored >= 0
? "0x${ored.toRadixString(16)}"
: "-0x${(-ored).toRadixString(16)}";
Expect.equals(result.toLowerCase(), str_ored);
int ored2 = int_b | int_a;
Expect.equals(int_result, ored2);
String str_ored2 = ored2 >= 0
? "0x${ored2.toRadixString(16)}"
: "-0x${(-ored2).toRadixString(16)}";
Expect.equals(result.toLowerCase(), str_ored2);
}
testBigintBitOr() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
bitOrParsed(one, zero, one);
bitOrParsed(one, one, one);
bitOrParsed(minus_one, zero, minus_one);
bitOrParsed(minus_one, one, minus_one);
bitOrParsed(minus_one, minus_one, minus_one);
bitOrParsed("-0x3", one, "-0x3");
bitOrParsed("0x5", "0x3", "0x7");
bitOrParsed("0x5", minus_one, minus_one);
bitOrParsed("0x5", zero, "0x5");
bitOrParsed("0x50000000", one, "0x50000001");
bitOrParsed("0x50000000", minus_one, minus_one);
bitOrParsed("0x500000000", one, "0x500000001");
bitOrParsed("0x500000000", minus_one, minus_one);
bitOrParsed("0x50000000000000000", one, "0x50000000000000001");
bitOrParsed("0x50000000000000000", minus_one, minus_one);
bitOrParsed("-0x50000000", "-0x50000000", "-0x50000000");
bitOrParsed("-0x500000000", "-0x500000000", "-0x500000000");
bitOrParsed(
"-0x50000000000000000", "-0x50000000000000000", "-0x50000000000000000");
bitOrParsed("0x1234567890ABCDEF012345678", "0x876543210FEDCBA0987654321",
"0x977557799FEFCFEF997755779");
bitOrParsed("-0x1234567890ABCDEF012345678", "-0x876543210FEDCBA0987654321",
"-0x224422000A9C9A0002244221");
bitOrParsed("0x1234567890ABCDEF012345678", "-0x876543210FEDCBA0987654321",
"-0x854101010F440200985410101");
bitOrParsed("0x1234567890ABCDEF012345678FFFFFFFFFFFFFFFFFFFFFFFFF",
"-0x876543210FEDCBA0987654321", "-0x1");
bitOrParsed("0x12345678", "0xFFFFFFF", "0x1FFFFFFF");
bitOrParsed("0x123456789", "0xFFFFFFFF", "0x1FFFFFFFF");
bitOrParsed("-0x10000000", "0xFFFFFFF", "-0x1");
bitOrParsed("-0x100000000", "0xFFFFFFFF", "-0x1");
bitOrParsed("-0x10000001", "0xFFFFFFF", "-0x10000001");
bitOrParsed("-0x100000001", "0xFFFFFFFF", "-0x100000001");
bitOrParsed("-0x10000001", "0x3FFFFFFF", "-0x1");
bitOrParsed("-0x100000001", "0x3FFFFFFFF", "-0x1");
bitOrParsed("-0x10000000000000001", "0x3FFFFFFFFFFFFFFFF", "-0x1");
bitOrParsed("-0x100000000000000", "0xFFFFFFFFFFFFFF", "-0x1");
bitOrParsed("-0x10000000000000000", "0xFFFFFFFFFFFFFFFF", "-0x1");
bitOrParsed("-0x300000000000000", "0xFFFFFFFFFFFFFFF", "-0x1");
bitOrParsed("-0x30000000000000000", "0xFFFFFFFFFFFFFFFFF", "-0x1");
bitOrParsed("-0x10000000", "-0x10000000", "-0x10000000");
bitOrParsed("-0x100000000", "-0x100000000", "-0x100000000");
bitOrParsed("-0x100000000000000", "-0x100000000000000", "-0x100000000000000");
bitOrParsed(
"-0x10000000000000000", "-0x10000000000000000", "-0x10000000000000000");
bitOrParsed("-0x10000000", "-0x10000001", "-0x1");
bitOrParsed("-0x100000000", "-0x100000001", "-0x1");
bitOrParsed("-0x100000000000000", "-0x100000000000001", "-0x1");
bitOrParsed("-0x10000000000000000", "-0x10000000000000001", "-0x1");
bitOrParsed("-0x10000000000000000", "-0x1", "-0x1");
}
bitXorParsed(String a, String b, String result) {
int int_a = int.parse(a);
int int_b = int.parse(b);
int int_result = int.parse(result);
int xored = int_a ^ int_b;
Expect.equals(int_result, xored);
String str_xored = xored >= 0
? "0x${xored.toRadixString(16)}"
: "-0x${(-xored).toRadixString(16)}";
Expect.equals(result.toLowerCase(), str_xored);
int xored2 = int_b ^ int_a;
Expect.equals(int_result, xored2);
String str_xored2 = xored2 >= 0
? "0x${xored2.toRadixString(16)}"
: "-0x${(-xored2).toRadixString(16)}";
Expect.equals(result.toLowerCase(), str_xored2);
int xored3 = int_a ^ xored2;
Expect.equals(int_b, xored3);
String str_xored3 = xored3 >= 0
? "0x${xored3.toRadixString(16)}"
: "-0x${(-xored3).toRadixString(16)}";
Expect.equals(b.toLowerCase(), str_xored3);
}
testBigintBitXor() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
bitXorParsed(one, zero, one);
bitXorParsed(one, one, zero);
bitXorParsed(minus_one, zero, minus_one);
bitXorParsed(minus_one, one, "-0x2");
bitXorParsed(minus_one, minus_one, zero);
bitXorParsed("0x5", "0x3", "0x6");
bitXorParsed("0x5", minus_one, "-0x6");
bitXorParsed("0x5", zero, "0x5");
bitXorParsed(minus_one, "-0x8", "0x7");
bitXorParsed("0x50000000", one, "0x50000001");
bitXorParsed("0x50000000", minus_one, "-0x50000001");
bitXorParsed("0x500000000", one, "0x500000001");
bitXorParsed("0x500000000", minus_one, "-0x500000001");
bitXorParsed("0x50000000000000000", one, "0x50000000000000001");
bitXorParsed("0x50000000000000000", minus_one, "-0x50000000000000001");
bitXorParsed("-0x50000000", "-0x50000000", zero);
bitXorParsed("-0x500000000", "-0x500000000", zero);
bitXorParsed("-0x50000000000000000", "-0x50000000000000000", zero);
bitXorParsed("0x1234567890ABCDEF012345678", "0x876543210FEDCBA0987654321",
"0x955115599F46064F995511559");
bitXorParsed("-0x1234567890ABCDEF012345678", "-0x876543210FEDCBA0987654321",
"0x955115599F46064F995511557");
bitXorParsed("0x1234567890ABCDEF012345678", "-0x876543210FEDCBA0987654321",
"-0x955115599F46064F995511559");
bitXorParsed(
"0x1234567890ABCDEF012345678FFFFFFFFFFFFFFFFFFFFFFFFF",
"-0x876543210FEDCBA0987654321",
"-0x1234567890ABCDEF012345678789ABCDEF012345F6789ABCE0");
bitXorParsed("0x12345678", "0xFFFFFFF", "0x1DCBA987");
bitXorParsed("0x123456789", "0xFFFFFFFF", "0x1DCBA9876");
bitXorParsed("-0x10000000", "0xFFFFFFF", "-0x1");
bitXorParsed("-0x100000000", "0xFFFFFFFF", "-0x1");
bitXorParsed("-0x10000001", "0xFFFFFFF", "-0x20000000");
bitXorParsed("-0x100000001", "0xFFFFFFFF", "-0x200000000");
bitXorParsed("-0x10000001", "0x3FFFFFFF", "-0x30000000");
bitXorParsed("-0x100000001", "0x3FFFFFFFF", "-0x300000000");
bitXorParsed(
"-0x10000000000000001", "0x3FFFFFFFFFFFFFFFF", "-0x30000000000000000");
bitXorParsed("-0x100000000000000", "0xFFFFFFFFFFFFFF", "-0x1");
bitXorParsed("-0x10000000000000000", "0xFFFFFFFFFFFFFFFF", "-0x1");
bitXorParsed("-0x300000000000000", "0xFFFFFFFFFFFFFFF", "-0xD00000000000001");
bitXorParsed(
"-0x30000000000000000", "0xFFFFFFFFFFFFFFFFF", "-0xD0000000000000001");
bitXorParsed("-0x10000000", "-0x10000000", zero);
bitXorParsed("-0x100000000", "-0x100000000", zero);
bitXorParsed("-0x100000000000000", "-0x100000000000000", zero);
bitXorParsed("-0x10000000000000000", "-0x10000000000000000", zero);
bitXorParsed("-0x10000000", "-0x10000001", "0x1FFFFFFF");
bitXorParsed("-0x100000000", "-0x100000001", "0x1FFFFFFFF");
bitXorParsed("-0x100000000000000", "-0x100000000000001", "0x1FFFFFFFFFFFFFF");
bitXorParsed(
"-0x10000000000000000", "-0x10000000000000001", "0x1FFFFFFFFFFFFFFFF");
}
bitNotParsed(String a, String result) {
int int_a = int.parse(a);
int int_result = int.parse(result);
int inverted = ~int_a;
Expect.equals(int_result, inverted);
String str_inverted = inverted >= 0
? "0x${inverted.toRadixString(16)}"
: "-0x${(-inverted).toRadixString(16)}";
Expect.equals(result.toLowerCase(), str_inverted);
int back = ~inverted;
Expect.equals(int_a, back);
String str_back = back >= 0
? "0x${back.toRadixString(16)}"
: "-0x${(-back).toRadixString(16)}";
Expect.equals(a.toLowerCase(), str_back);
}
testBigintBitNot() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
bitNotParsed(zero, minus_one);
bitNotParsed(one, "-0x2");
bitNotParsed("0x5", "-0x6");
bitNotParsed("0x50000000", "-0x50000001");
bitNotParsed("0xFFFFFFF", "-0x10000000");
bitNotParsed("0xFFFFFFFF", "-0x100000000");
bitNotParsed("0xFFFFFFFFFFFFFF", "-0x100000000000000");
bitNotParsed("0xFFFFFFFFFFFFFFFF", "-0x10000000000000000");
bitNotParsed("0x1234567890ABCDEF012345678", "-0x1234567890ABCDEF012345679");
}
main() {
testBigintAddSub();
testBigintLeftShift();
testBigintRightShift();
testBigintBitAnd();
testBigintBitOr();
testBigintBitXor();
testBigintBitNot();
}

View file

@ -8,7 +8,6 @@
# Skip tests that are not yet strong-mode clean.
[ $strong ]
big_integer_arith_vm_test: Skip
bool_from_environment2_test: Skip
core_runtime_types_test: Skip
data_resource_test: Skip
@ -56,9 +55,6 @@ uri_path_test: Skip
uri_query_test: Skip
[ $compiler == dartdevc ]
apply2_test: RuntimeError # Issue 29921
apply3_test: RuntimeError # Issue 29921
big_integer_parsed_arith_vm_test: RuntimeError # Issue 29921
big_integer_parsed_div_rem_vm_test: RuntimeError # Issue 29921
big_integer_parsed_mul_div_vm_test: RuntimeError # Issue 29921
bit_twiddling_bigint_test: RuntimeError # Issue 29921