|
6 | 6 | public class GCDTest { |
7 | 7 |
|
8 | 8 | @Test |
9 | | - void test1() { |
| 9 | + void testNegativeAndZeroThrowsException() { |
10 | 10 | Assertions.assertThrows(ArithmeticException.class, () -> GCD.gcd(-1, 0)); |
11 | 11 | } |
12 | 12 |
|
13 | 13 | @Test |
14 | | - void test2() { |
| 14 | + void testPositiveAndNegativeThrowsException() { |
15 | 15 | Assertions.assertThrows(ArithmeticException.class, () -> GCD.gcd(10, -2)); |
16 | 16 | } |
17 | 17 |
|
18 | 18 | @Test |
19 | | - void test3() { |
| 19 | + void testBothNegativeThrowsException() { |
20 | 20 | Assertions.assertThrows(ArithmeticException.class, () -> GCD.gcd(-5, -3)); |
21 | 21 | } |
22 | 22 |
|
23 | 23 | @Test |
24 | | - void test4() { |
25 | | - Assertions.assertEquals(GCD.gcd(0, 2), 2); |
| 24 | + void testZeroAndPositiveReturnsPositive() { |
| 25 | + Assertions.assertEquals(2, GCD.gcd(0, 2)); |
26 | 26 | } |
27 | 27 |
|
28 | 28 | @Test |
29 | | - void test5() { |
30 | | - Assertions.assertEquals(GCD.gcd(10, 0), 10); |
| 29 | + void testPositiveAndZeroReturnsPositive() { |
| 30 | + Assertions.assertEquals(10, GCD.gcd(10, 0)); |
31 | 31 | } |
32 | 32 |
|
33 | 33 | @Test |
34 | | - void test6() { |
35 | | - Assertions.assertEquals(GCD.gcd(1, 0), 1); |
| 34 | + void testOneAndZeroReturnsOne() { |
| 35 | + Assertions.assertEquals(1, GCD.gcd(1, 0)); |
36 | 36 | } |
37 | 37 |
|
38 | 38 | @Test |
39 | | - void test7() { |
40 | | - Assertions.assertEquals(GCD.gcd(9, 6), 3); |
| 39 | + void testTwoPositiveNumbers() { |
| 40 | + Assertions.assertEquals(3, GCD.gcd(9, 6)); |
41 | 41 | } |
42 | 42 |
|
43 | 43 | @Test |
44 | | - void test8() { |
45 | | - Assertions.assertEquals(GCD.gcd(48, 18, 30, 12), 6); |
| 44 | + void testMultipleArgumentsGcd() { |
| 45 | + Assertions.assertEquals(6, GCD.gcd(48, 18, 30, 12)); |
46 | 46 | } |
47 | 47 |
|
48 | 48 | @Test |
49 | | - void testArrayGcd1() { |
50 | | - Assertions.assertEquals(GCD.gcd(new int[] {9, 6}), 3); |
| 49 | + void testArrayInputGcd() { |
| 50 | + Assertions.assertEquals(3, GCD.gcd(new int[] {9, 6})); |
51 | 51 | } |
52 | 52 |
|
53 | 53 | @Test |
54 | | - void testArrayGcd2() { |
55 | | - Assertions.assertEquals(GCD.gcd(new int[] {2 * 3 * 5 * 7, 2 * 5 * 5 * 5, 2 * 5 * 11, 5 * 5 * 5 * 13}), 5); |
| 54 | + void testArrayWithCommonFactor() { |
| 55 | + Assertions.assertEquals(5, GCD.gcd(new int[] {2 * 3 * 5 * 7, 2 * 5 * 5 * 5, 2 * 5 * 11, 5 * 5 * 5 * 13})); |
56 | 56 | } |
57 | 57 |
|
58 | 58 | @Test |
59 | | - void testArrayGcdForEmptyInput() { |
60 | | - Assertions.assertEquals(GCD.gcd(new int[] {}), 0); |
| 59 | + void testEmptyArrayReturnsZero() { |
| 60 | + Assertions.assertEquals(0, GCD.gcd(new int[] {})); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + void testSameNumbers() { |
| 65 | + Assertions.assertEquals(7, GCD.gcd(7, 7)); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + void testPrimeNumbersHaveGcdOne() { |
| 70 | + Assertions.assertEquals(1, GCD.gcd(13, 17)); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + void testSingleElementArrayReturnsElement() { |
| 75 | + Assertions.assertEquals(42, GCD.gcd(new int[] {42})); |
| 76 | + } |
| 77 | + |
| 78 | + @Test |
| 79 | + void testLargeNumbers() { |
| 80 | + Assertions.assertEquals(12, GCD.gcd(123456, 789012)); |
61 | 81 | } |
62 | 82 | } |
0 commit comments