|
| 1 | +package com.thealgorithms.maths; |
| 2 | + |
| 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; |
| 6 | + |
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | + |
| 9 | +public class GoldbachConjectureTest { |
| 10 | + @Test |
| 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 |
| 16 | + } |
| 17 | + @Test |
| 18 | + void testInvalidOddNumbers() { |
| 19 | + assertThrows(IllegalArgumentException.class, () -> getPrimeSum(7)); |
| 20 | + assertThrows(IllegalArgumentException.class, () -> getPrimeSum(15)); |
| 21 | + } |
| 22 | + @Test |
| 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)); |
| 28 | + } |
| 29 | +} |
0 commit comments