|
1 | 1 | package com.thealgorithms.maths; |
2 | 2 |
|
3 | 3 | import static com.thealgorithms.maths.GoldbachConjecture.getPrimeSum; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
4 | 6 |
|
5 | | -import org.junit.jupiter.api.Assertions; |
6 | 7 | import org.junit.jupiter.api.Test; |
7 | 8 |
|
8 | 9 | public class GoldbachConjectureTest { |
9 | 10 | @Test |
10 | | - void goldbachTestWithZero() { |
11 | | - Assertions.assertEquals("Wrong Input", getPrimeSum(0)); |
| 11 | + void testValidEvenNumbers() { |
| 12 | + assertEquals(new GoldbachConjecture.Result(3, 7), getPrimeSum(10)); // 10 = 3 + 7 |
| 13 | + assertEquals(new GoldbachConjecture.Result(5, 7), getPrimeSum(12)); // 12 = 5 + 7 |
| 14 | + assertEquals(new GoldbachConjecture.Result(3, 11), getPrimeSum(14)); // 14 = 3 + 11 |
| 15 | + assertEquals(new GoldbachConjecture.Result(5, 13), getPrimeSum(18)); // 18 = 5 + 13 |
12 | 16 | } |
13 | 17 | @Test |
14 | | - void goldbachTestWithNegative() { |
15 | | - Assertions.assertEquals("Wrong Input", getPrimeSum(-50)); |
| 18 | + void testInvalidOddNumbers() { |
| 19 | + assertThrows(IllegalArgumentException.class, () -> getPrimeSum(7)); |
| 20 | + assertThrows(IllegalArgumentException.class, () -> getPrimeSum(15)); |
16 | 21 | } |
17 | 22 | @Test |
18 | | - void goldbachTestWith2() { |
19 | | - Assertions.assertEquals("Wrong Input", getPrimeSum(2)); |
20 | | - } |
21 | | - @Test |
22 | | - void goldbachTestWithOdd() { |
23 | | - Assertions.assertEquals("Wrong Input", getPrimeSum(25)); |
24 | | - } |
25 | | - @Test |
26 | | - void goldbachTestEven1() { |
27 | | - Assertions.assertEquals("3 + 5 = 8", getPrimeSum(8)); |
28 | | - } |
29 | | - @Test |
30 | | - void goldbachTestEven2() { |
31 | | - Assertions.assertEquals("3 + 19 = 22", getPrimeSum(22)); |
32 | | - } |
33 | | - @Test |
34 | | - void goldbachTest1() { |
35 | | - Assertions.assertEquals("3 + 7 = 10", getPrimeSum(10)); |
| 23 | + void testLesserThanTwo() { |
| 24 | + assertThrows(IllegalArgumentException.class, () -> getPrimeSum(1)); |
| 25 | + assertThrows(IllegalArgumentException.class, () -> getPrimeSum(2)); |
| 26 | + assertThrows(IllegalArgumentException.class, () -> getPrimeSum(-5)); |
| 27 | + assertThrows(IllegalArgumentException.class, () -> getPrimeSum(-26)); |
36 | 28 | } |
37 | 29 | } |
0 commit comments