-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathGreatestCommonDivisorTests.cs
88 lines (76 loc) · 2.79 KB
/
GreatestCommonDivisorTests.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using Algorithms.Numeric;
using Xunit;
namespace UnitTest.AlgorithmsTests
{
public class GreatestCommonDivisorTests
{
[Fact]
public void FindGCD_BothAreZero()
{
var gcdEuclidean = GreatestCommonDivisor.FindGCDEuclidean(0, 0);
Assert.Equal(0, gcdEuclidean);
var gcdStein = GreatestCommonDivisor.FindGCDStein(0, 0);
Assert.Equal(0, gcdStein);
}
[Theory]
[InlineData(0, 4, 4)]
[InlineData(0, 9, 9)]
[InlineData(0, -14, 14)]
[InlineData(0, -99, 99)]
public void FindGCD_FirstIsZero(int a, int b, int expected)
{
var gcdEuclidean = GreatestCommonDivisor.FindGCDEuclidean(a, b);
Assert.Equal(expected, gcdEuclidean);
var gcdStein = GreatestCommonDivisor.FindGCDStein(a, b);
Assert.Equal(expected, gcdStein);
}
[Theory]
[InlineData(4, 0, 4)]
[InlineData(9, 0, 9)]
[InlineData(-14, 0, 14)]
[InlineData(-99, 0, 99)]
public void FindGCD_SecondIsZero(int a, int b, int expected)
{
var gcdEuclidean = GreatestCommonDivisor.FindGCDEuclidean(a, b);
Assert.Equal(expected, gcdEuclidean);
var gcdStein = GreatestCommonDivisor.FindGCDStein(a, b);
Assert.Equal(expected, gcdStein);
}
[Theory]
[InlineData(2, 4, 2)]
[InlineData(27, 9, 9)]
[InlineData(27, 14, 1)]
[InlineData(9, 6, 3)]
public void FindGCD_BothNumberArePositive(int a, int b, int expected)
{
var gcdEuclidean = GreatestCommonDivisor.FindGCDEuclidean(a, b);
Assert.Equal(expected, gcdEuclidean);
var gcdStein = GreatestCommonDivisor.FindGCDStein(a, b);
Assert.Equal(expected, gcdStein);
}
[Theory]
[InlineData(-2, -4, 2)]
[InlineData(-27, -9, 9)]
[InlineData(-27, -14, 1)]
[InlineData(-9, -6, 3)]
public void FindGCD_BothNumberAreNegative(int a, int b, int expected)
{
var gcdEuclidean = GreatestCommonDivisor.FindGCDEuclidean(a, b);
Assert.Equal(expected, gcdEuclidean);
var gcdStein = GreatestCommonDivisor.FindGCDStein(a, b);
Assert.Equal(expected, gcdStein);
}
[Theory]
[InlineData(2, -4, 2)]
[InlineData(-27, 9, 9)]
[InlineData(27, -14, 1)]
[InlineData(-9, 6, 3)]
public void FindGCD_CombinationPositiveAndNegative(int a, int b, int expected)
{
var gcdEuclidean = GreatestCommonDivisor.FindGCDEuclidean(a, b);
Assert.Equal(expected, gcdEuclidean);
var gcdStein = GreatestCommonDivisor.FindGCDStein(a, b);
Assert.Equal(expected, gcdStein);
}
}
}