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 Expect.equals(1, powmod(2, 0, 13)); | |
18 Expect.equals(1, powmod(-5, 0, 7)); | |
19 Expect.equals(1, powmod(2, 0, -9)); | |
20 | |
21 // Negative base | |
22 Expect.equals(1, powmod(-2, 0, 7)); | |
23 Expect.equals(5, powmod(-2, 1, 7)); | |
24 Expect.equals(6, powmod(-2, 3, 7)); | |
25 | |
26 // Negative power (inverse modulo) | |
27 Expect.equals(4, powmod(2, -1, 7)); | |
28 Expect.equals(2, powmod(2, -2, 7)); | |
29 Expect.equals(1, powmod(2, -3, 7)); | |
30 | |
31 // Negative modulus (should behave like % operator) | |
32 Expect.equals(1, powmod(2, 0, -7)); | |
33 Expect.equals(2, powmod(2, 1, -7)); | |
34 Expect.equals(4, powmod(2, 2, -7)); | |
35 | |
36 Expect.throws(() => powmod(0, null, 0), (e) => e is ArgumentError); | |
37 Expect.throws(() => powmod(null, 0, 0), (e) => e is ArgumentError); | |
38 Expect.throws(() => powmod(0, 0, null), (e) => e is ArgumentError); | |
39 | |
40 // Medium int (mint) arguments smaller than 94906266. | |
41 // 67108879 is the first prime after 2^26. | |
42 Expect.equals(1048576, powmod(pow(2, 20), 1, 67108879)); | |
43 Expect.equals(66863119, powmod(pow(2, 20), 2, 67108879)); | |
44 Expect.equals(57600, powmod(pow(2, 20), 3, 67108879)); | |
45 Expect.equals(67095379, powmod(pow(2, 20), 4, 67108879)); | |
46 Expect.equals(4197469, powmod(pow(2, 20), 5, 67108879)); | |
47 } | |
48 | |
49 main() { | |
50 testPowmod(); | |
51 } | |
OLD | NEW |