OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library math_test; |
| 6 import "package:expect/expect.dart"; |
| 7 import 'dart:math'; |
| 8 import 'package:math/math.dart'; |
| 9 |
| 10 void testPowmod() { |
| 11 Expect.equals(1, powmod(2, 0, 7)); |
| 12 Expect.equals(2, powmod(2, 1, 7)); |
| 13 Expect.equals(4, powmod(2, 2, 7)); |
| 14 Expect.equals(1, powmod(2, 3, 7)); |
| 15 Expect.equals(2, powmod(2, 4, 7)); |
| 16 |
| 17 // Negative base |
| 18 Expect.equals(1, powmod(-2, 0, 7)); |
| 19 Expect.equals(5, powmod(-2, 1, 7)); |
| 20 Expect.equals(6, powmod(-2, 3, 7)); |
| 21 |
| 22 // Negative power (inverse modulo) |
| 23 Expect.equals(4, powmod(2, -1, 7)); |
| 24 Expect.equals(2, powmod(2, -2, 7)); |
| 25 Expect.equals(1, powmod(2, -3, 7)); |
| 26 |
| 27 // Negative modulus (should behave like % operator) |
| 28 Expect.equals(1, powmod(2, 0, -7)); |
| 29 Expect.equals(2, powmod(2, 1, -7)); |
| 30 Expect.equals(4, powmod(2, 2, -7)); |
| 31 |
| 32 Expect.throws(() => powmod(0, null, 0), (e) => e is ArgumentError); |
| 33 Expect.throws(() => powmod(null, 0, 0), (e) => e is ArgumentError); |
| 34 Expect.throws(() => powmod(0, 0, null), (e) => e is ArgumentError); |
| 35 |
| 36 // Medium int (mint) arguments smaller than 94906266. |
| 37 // 67108879 is the first prime after 2^26. |
| 38 Expect.equals(1048576, powmod(pow(2, 20), 1, 67108879)); |
| 39 Expect.equals(66863119, powmod(pow(2, 20), 2, 67108879)); |
| 40 Expect.equals(57600, powmod(pow(2, 20), 3, 67108879)); |
| 41 Expect.equals(67095379, powmod(pow(2, 20), 4, 67108879)); |
| 42 Expect.equals(4197469, powmod(pow(2, 20), 5, 67108879)); |
| 43 } |
| 44 |
| 45 main() { |
| 46 testPowmod(); |
| 47 } |
OLD | NEW |