-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathModularMultiplicativeInverseTest.cs
63 lines (54 loc) · 1.64 KB
/
ModularMultiplicativeInverseTest.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
53
54
55
56
57
58
59
60
61
62
63
using Algorithms.ModularArithmetic;
using NUnit.Framework;
using System;
using System.Numerics;
namespace Algorithms.Tests.ModularArithmetic;
public static class ModularMultiplicativeInverseTest
{
[TestCase(2, 3, 2)]
[TestCase(1, 1, 0)]
[TestCase(13, 17, 4)]
public static void TestCompute(long a, long n, long expected)
{
// Act
var inverse = ModularMultiplicativeInverse.Compute(a, n);
// Assert
Assert.That(inverse, Is.EqualTo(expected));
}
[TestCase(46, 240)]
[TestCase(0, 17)]
[TestCase(17, 0)]
[TestCase(17, 17)]
[TestCase(0, 0)]
[TestCase(2 * 13 * 17, 4 * 9 * 13)]
public static void TestCompute_Irrevertible(long a, long n)
{
// Act
void Act() => ModularMultiplicativeInverse.Compute(a, n);
// Assert
_ = Assert.Throws<ArithmeticException>(Act);
}
[TestCase(2, 3, 2)]
[TestCase(1, 1, 0)]
[TestCase(13, 17, 4)]
public static void TestCompute_BigInteger(long a, long n, long expected)
{
// Act
var inverse = ModularMultiplicativeInverse.Compute(new BigInteger(a), new BigInteger(n));
// Assert
Assert.That(inverse, Is.EqualTo(new BigInteger(expected)));
}
[TestCase(46, 240)]
[TestCase(0, 17)]
[TestCase(17, 0)]
[TestCase(17, 17)]
[TestCase(0, 0)]
[TestCase(2 * 13 * 17, 4 * 9 * 13)]
public static void TestCompute_BigInteger_Irrevertible(long a, long n)
{
// Act
void Act() => ModularMultiplicativeInverse.Compute(new BigInteger(a), new BigInteger(n));
// Assert
_ = Assert.Throws<ArithmeticException>(Act);
}
}