Skip to content

Commit 742bcc7

Browse files
committed
Rename GCD test methods and add descriptive names
1 parent 30dcc4c commit 742bcc7

File tree

1 file changed

+43
-39
lines changed

1 file changed

+43
-39
lines changed

src/test/java/com/thealgorithms/maths/GCDTest.java

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,81 +6,85 @@
66
public class GCDTest {
77

88
@Test
9-
void test1() {
9+
void testNegativeAndZeroThrowsException() {
1010
Assertions.assertThrows(ArithmeticException.class, () -> GCD.gcd(-1, 0));
1111
}
1212

1313
@Test
14-
void test2() {
14+
void testPositiveAndNegativeThrowsException() {
1515
Assertions.assertThrows(ArithmeticException.class, () -> GCD.gcd(10, -2));
1616
}
1717

1818
@Test
19-
void test3() {
19+
void testBothNegativeThrowsException() {
2020
Assertions.assertThrows(ArithmeticException.class, () -> GCD.gcd(-5, -3));
2121
}
2222

2323
@Test
24-
void test4() {
25-
Assertions.assertEquals(GCD.gcd(0, 2), 2);
24+
void testZeroAndPositiveReturnsPositive() {
25+
Assertions.assertEquals(2, GCD.gcd(0, 2));
2626
}
2727

2828
@Test
29-
void test5() {
30-
Assertions.assertEquals(GCD.gcd(10, 0), 10);
29+
void testPositiveAndZeroReturnsPositive() {
30+
Assertions.assertEquals(10, GCD.gcd(10, 0));
3131
}
3232

3333
@Test
34-
void test6() {
35-
Assertions.assertEquals(GCD.gcd(1, 0), 1);
34+
void testOneAndZeroReturnsOne() {
35+
Assertions.assertEquals(1, GCD.gcd(1, 0));
3636
}
3737

3838
@Test
39-
void test7() {
40-
Assertions.assertEquals(GCD.gcd(9, 6), 3);
39+
void testTwoPositiveNumbers() {
40+
Assertions.assertEquals(3, GCD.gcd(9, 6));
4141
}
4242

4343
@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));
4646
}
4747

4848
@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}));
5151
}
5252

5353
@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(
56+
5,
57+
GCD.gcd(new int[] {
58+
2 * 3 * 5 * 7,
59+
2 * 5 * 5 * 5,
60+
2 * 5 * 11,
61+
5 * 5 * 5 * 13
62+
})
63+
);
5664
}
5765

5866
@Test
59-
void testArrayGcdForEmptyInput() {
60-
Assertions.assertEquals(GCD.gcd(new int[] {}), 0);
67+
void testEmptyArrayReturnsZero() {
68+
Assertions.assertEquals(0, GCD.gcd(new int[] {}));
6169
}
6270

63-
64-
65-
66-
@Test
67-
void testSameNumbers() {
68-
Assertions.assertEquals(GCD.gcd(7, 7), 7);
69-
}
70-
71-
@Test
72-
void testPrimeNumbers() {
73-
Assertions.assertEquals(GCD.gcd(13, 17), 1);
74-
}
71+
@Test
72+
void testSameNumbers() {
73+
Assertions.assertEquals(7, GCD.gcd(7, 7));
74+
}
7575

76-
@Test
77-
void testSingleElementArray() {
78-
Assertions.assertEquals(GCD.gcd(new int[] {42}), 42);
79-
}
76+
@Test
77+
void testPrimeNumbersHaveGcdOne() {
78+
Assertions.assertEquals(1, GCD.gcd(13, 17));
79+
}
8080

81-
@Test
82-
void testLargeNumbers() {
83-
Assertions.assertEquals(GCD.gcd(123456, 789012), 12);
84-
}
81+
@Test
82+
void testSingleElementArrayReturnsElement() {
83+
Assertions.assertEquals(42, GCD.gcd(new int[] {42}));
84+
}
8585

86+
@Test
87+
void testLargeNumbers() {
88+
Assertions.assertEquals(12, GCD.gcd(123456, 789012));
89+
}
8690
}

0 commit comments

Comments
 (0)