-
Notifications
You must be signed in to change notification settings - Fork 19.7k
/
Copy pathGCDTest.java
62 lines (49 loc) · 1.29 KB
/
GCDTest.java
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
package com.thealgorithms.maths;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class GCDTest {
@Test
void test1() {
Assertions.assertThrows(ArithmeticException.class, () -> GCD.gcd(-1, 0));
}
@Test
void test2() {
Assertions.assertThrows(ArithmeticException.class, () -> GCD.gcd(10, -2));
}
@Test
void test3() {
Assertions.assertThrows(ArithmeticException.class, () -> GCD.gcd(-5, -3));
}
@Test
void test4() {
Assertions.assertEquals(GCD.gcd(0, 2), 2);
}
@Test
void test5() {
Assertions.assertEquals(GCD.gcd(10, 0), 10);
}
@Test
void test6() {
Assertions.assertEquals(GCD.gcd(1, 0), 1);
}
@Test
void test7() {
Assertions.assertEquals(GCD.gcd(9, 6), 3);
}
@Test
void test8() {
Assertions.assertEquals(GCD.gcd(48, 18, 30, 12), 6);
}
@Test
void testArrayGcd1() {
Assertions.assertEquals(GCD.gcd(new int[] {9, 6}), 3);
}
@Test
void testArrayGcd2() {
Assertions.assertEquals(GCD.gcd(new int[] {2 * 3 * 5 * 7, 2 * 5 * 5 * 5, 2 * 5 * 11, 5 * 5 * 5 * 13}), 5);
}
@Test
void testArrayGcdForEmptyInput() {
Assertions.assertEquals(GCD.gcd(new int[] {}), 0);
}
}