-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathExtendedEuclideanAlgorithmTest.cs
52 lines (47 loc) · 1.86 KB
/
ExtendedEuclideanAlgorithmTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using Algorithms.ModularArithmetic;
using NUnit.Framework;
using System.Numerics;
namespace Algorithms.Tests.ModularArithmetic;
public static class ExtendedEuclideanAlgorithmTest
{
[TestCase(240, 46, 2, -9, 47)]
[TestCase(46, 240, 2, 47, -9)]
[TestCase(2, 3, 1, -1, 1)]
[TestCase(1, 1, 1, 0, 1)]
[TestCase(13, 17, 1, 4, -3)]
[TestCase(0, 17, 17, 0, 1)]
[TestCase(17, 0, 17, 1, 0)]
[TestCase(17, 17, 17, 0, 1)]
[TestCase(2 * 17, 17, 17, 0, 1)]
[TestCase(0, 0, 0, 1, 0)]
[TestCase(2 * 13 * 17, 4 * 9 * 13, 2 * 13, -1, 1)]
public static void TestCompute(long a, long b, long expectedGCD, long expectedBezoutOfA, long expectedBezoutOfB)
{
// Act
var eeaResult = ExtendedEuclideanAlgorithm.Compute(a, b);
// Assert
Assert.That(eeaResult.Gcd, Is.EqualTo(expectedGCD));
Assert.That(eeaResult.BezoutA, Is.EqualTo(expectedBezoutOfA));
Assert.That(eeaResult.BezoutB, Is.EqualTo(expectedBezoutOfB));
}
[TestCase(240, 46, 2, -9, 47)]
[TestCase(46, 240, 2, 47, -9)]
[TestCase(2, 3, 1, -1, 1)]
[TestCase(1, 1, 1, 0, 1)]
[TestCase(13, 17, 1, 4, -3)]
[TestCase(0, 17, 17, 0, 1)]
[TestCase(17, 0, 17, 1, 0)]
[TestCase(17, 17, 17, 0, 1)]
[TestCase(2 * 17, 17, 17, 0, 1)]
[TestCase(0, 0, 0, 1, 0)]
[TestCase(2 * 13 * 17, 4 * 9 * 13, 2 * 13, -1, 1)]
public static void TestCompute_BigInteger(long a, long b, long expectedGCD, long expectedBezoutOfA, long expectedBezoutOfB)
{
// Act
var eeaResult = ExtendedEuclideanAlgorithm.Compute(new BigInteger(a), new BigInteger(b));
// Assert
Assert.That(eeaResult.Gcd, Is.EqualTo(new BigInteger(expectedGCD)));
Assert.That(eeaResult.BezoutA, Is.EqualTo(new BigInteger(expectedBezoutOfA)));
Assert.That(eeaResult.BezoutB, Is.EqualTo(new BigInteger(expectedBezoutOfB)));
}
}