Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21.3k
Expand file tree
/
Copy pathGCDTest.java
More file actions
Latest commit
82 lines (65 loc) · 1.94 KB
/
Copy pathGCDTest.java
File metadata and controls
82 lines (65 loc) · 1.94 KB
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
packagecom.thealgorithms.maths;
importorg.junit.jupiter.api.Assertions;
importorg.junit.jupiter.api.Test;
publicclassGCDTest {
@Test
voidtestNegativeAndZeroThrowsException() {
Assertions.assertThrows(ArithmeticException.class, () -> GCD.gcd(-1, 0));
}
@Test
voidtestPositiveAndNegativeThrowsException() {
Assertions.assertThrows(ArithmeticException.class, () -> GCD.gcd(10, -2));
}
@Test
voidtestBothNegativeThrowsException() {
Assertions.assertThrows(ArithmeticException.class, () -> GCD.gcd(-5, -3));
}
@Test
voidtestZeroAndPositiveReturnsPositive() {
Assertions.assertEquals(2, GCD.gcd(0, 2));
}
@Test
voidtestPositiveAndZeroReturnsPositive() {
Assertions.assertEquals(10, GCD.gcd(10, 0));
}
@Test
voidtestOneAndZeroReturnsOne() {
Assertions.assertEquals(1, GCD.gcd(1, 0));
}
@Test
voidtestTwoPositiveNumbers() {
Assertions.assertEquals(3, GCD.gcd(9, 6));
}
@Test
voidtestMultipleArgumentsGcd() {
Assertions.assertEquals(6, GCD.gcd(48, 18, 30, 12));
}
@Test
voidtestArrayInputGcd() {
Assertions.assertEquals(3, GCD.gcd(newint[] {9, 6}));
}
@Test
voidtestArrayWithCommonFactor() {
Assertions.assertEquals(5, GCD.gcd(newint[] {2 * 3 * 5 * 7, 2 * 5 * 5 * 5, 2 * 5 * 11, 5 * 5 * 5 * 13}));
}
@Test
voidtestEmptyArrayReturnsZero() {
Assertions.assertEquals(0, GCD.gcd(newint[] {}));
}
@Test
voidtestSameNumbers() {
Assertions.assertEquals(7, GCD.gcd(7, 7));
}
@Test
voidtestPrimeNumbersHaveGcdOne() {
Assertions.assertEquals(1, GCD.gcd(13, 17));
}
@Test
voidtestSingleElementArrayReturnsElement() {
Assertions.assertEquals(42, GCD.gcd(newint[] {42}));
}
@Test
voidtestLargeNumbers() {
Assertions.assertEquals(12, GCD.gcd(123456, 789012));
}
}