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 testGcdext() { | |
11 Expect.listEquals([7, 0, 1], gcdext(0, 7)); | |
12 Expect.listEquals([5, 1, 0], gcdext(5, 0)); | |
13 Expect.listEquals([5, -1, 0], gcdext(-5, 0)); | |
14 Expect.listEquals([0, 1, 0], gcdext(0, 0)); | |
15 Expect.listEquals([1, 3, -2], gcdext(5, 7)); | |
16 Expect.listEquals([6, -1, 1], gcdext(12, 18)); | |
17 Expect.listEquals([6, -1, -1], gcdext(12, -18)); | |
18 Expect.listEquals([6, 1, -1], gcdext(-12, -18)); | |
19 Expect.listEquals([6, 1, -1], gcdext(18, 12)); | |
20 Expect.listEquals([15, -2, 1], gcdext(45, 105)); | |
21 | |
22 Expect.throws(() => gcdext(0, null), (e) => e is ArgumentError); | |
23 Expect.throws(() => gcdext(null, 0), (e) => e is ArgumentError); | |
24 | |
25 // Cover all branches in Binary GCD implementation. | |
26 | |
27 // Medium int (mint) arguments. | |
28 Expect.listEquals([pow(2, 60), 1, -1], gcdext(pow(2, 60)*5, pow(2, 62))); | |
29 Expect.listEquals([4000000000000, -96078, 96077], | |
30 gcdext(2305844000000000000, 2305868000000000000)); | |
31 // 9079837958533 is the first prime after 2**48 / 31. | |
32 Expect.listEquals([9079837958533, 6, -5], | |
33 gcdext(31*9079837958533, 37*9079837958533)); | |
34 } | |
35 | |
36 main() { | |
37 testGcdext(); | |
38 } | |
OLD | NEW |