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

Unified Diff: pkg/math/test/powmod_test.dart

Issue 475463005: Implement math.gcd in dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweaks Created 6 years, 3 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 | « pkg/math/test/lcm_test.dart ('k') | pkg/pkg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/math/test/powmod_test.dart
diff --git a/pkg/math/test/powmod_test.dart b/pkg/math/test/powmod_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ad47c4ad685efd82b0671481d70716864ad7eca2
--- /dev/null
+++ b/pkg/math/test/powmod_test.dart
@@ -0,0 +1,51 @@
+// Copyright (c) 2014, 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.
+
+library math_test;
+import "package:expect/expect.dart";
+import 'dart:math';
+import 'package:math/math.dart';
+
+void testPowmod() {
+ Expect.equals(1, powmod(2, 0, 7));
+ Expect.equals(2, powmod(2, 1, 7));
+ Expect.equals(4, powmod(2, 2, 7));
+ Expect.equals(1, powmod(2, 3, 7));
+ Expect.equals(2, powmod(2, 4, 7));
+
+ Expect.equals(1, powmod(2, 0, 13));
+ Expect.equals(1, powmod(-5, 0, 7));
+ Expect.equals(1, powmod(2, 0, -9));
+
+ // Negative base
+ Expect.equals(1, powmod(-2, 0, 7));
+ Expect.equals(5, powmod(-2, 1, 7));
+ Expect.equals(6, powmod(-2, 3, 7));
+
+ // Negative power (inverse modulo)
+ Expect.equals(4, powmod(2, -1, 7));
+ Expect.equals(2, powmod(2, -2, 7));
+ Expect.equals(1, powmod(2, -3, 7));
+
+ // Negative modulus (should behave like % operator)
+ Expect.equals(1, powmod(2, 0, -7));
+ Expect.equals(2, powmod(2, 1, -7));
+ Expect.equals(4, powmod(2, 2, -7));
+
+ Expect.throws(() => powmod(0, null, 0), (e) => e is ArgumentError);
+ Expect.throws(() => powmod(null, 0, 0), (e) => e is ArgumentError);
+ Expect.throws(() => powmod(0, 0, null), (e) => e is ArgumentError);
+
+ // Medium int (mint) arguments smaller than 94906266.
+ // 67108879 is the first prime after 2^26.
+ Expect.equals(1048576, powmod(pow(2, 20), 1, 67108879));
+ Expect.equals(66863119, powmod(pow(2, 20), 2, 67108879));
+ Expect.equals(57600, powmod(pow(2, 20), 3, 67108879));
+ Expect.equals(67095379, powmod(pow(2, 20), 4, 67108879));
+ Expect.equals(4197469, powmod(pow(2, 20), 5, 67108879));
+}
+
+main() {
+ testPowmod();
+}
« no previous file with comments | « pkg/math/test/lcm_test.dart ('k') | pkg/pkg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698