Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: tests/corelib/big_integer_arith_vm_test.dart

Issue 1199513003: Implement gcd in sdk. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/core/int.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/big_integer_arith_vm_test.dart
diff --git a/tests/corelib/big_integer_arith_vm_test.dart b/tests/corelib/big_integer_arith_vm_test.dart
index 3353756335d7e0ba3cc1354d32d8f5c6ea96b742..419e603d4c9cf840b9b6d15a36a3e9950d2d32e8 100644
--- a/tests/corelib/big_integer_arith_vm_test.dart
+++ b/tests/corelib/big_integer_arith_vm_test.dart
@@ -293,6 +293,88 @@ testBigintModInverse() {
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.throws(() => x.gcd(m), (e) => e is RangeError);
+ x = 1000000001;
+ m = 0;
+ Expect.throws(() => x.gcd(m), (e) => e is RangeError);
+ 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.
@@ -325,6 +407,7 @@ main() {
testBigintModulo();
testBigintModPow();
testBigintModInverse();
+ testBigintGcd();
testBigintNegate();
testShiftAmount();
Expect.equals(12345678901234567890, (12345678901234567890).abs());
« no previous file with comments | « sdk/lib/core/int.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698