- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathCatalanNumbersTest.java
43 lines (37 loc) · 1.64 KB
/
CatalanNumbersTest.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
packagecom.thealgorithms.maths;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importstaticorg.junit.jupiter.api.Assertions.assertThrows;
importjava.util.stream.Stream;
importorg.junit.jupiter.api.Test;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.MethodSource;
/**
* Test class for CatalanNumbers
*/
classCatalanNumbersTest {
/**
* Provides test data for the parameterized Catalan number test.
* Each array contains two elements:
* [input number, expected Catalan number for that input]
*/
staticStream<Object[]> catalanNumbersProvider() {
returnStream.of(newObject[] {0, 1}, newObject[] {1, 1}, newObject[] {2, 2}, newObject[] {3, 5}, newObject[] {4, 14}, newObject[] {5, 42}, newObject[] {6, 132}, newObject[] {7, 429}, newObject[] {8, 1430}, newObject[] {9, 4862}, newObject[] {10, 16796});
}
/**
* Parameterized test for checking the correctness of Catalan numbers.
* Uses the data from the provider method 'catalanNumbersProvider'.
*/
@ParameterizedTest
@MethodSource("catalanNumbersProvider")
voidtestCatalanNumbers(intinput, intexpected) {
assertEquals(expected, CatalanNumbers.catalan(input), () -> String.format("Catalan number for input %d should be %d", input, expected));
}
/**
* Test for invalid inputs which should throw an IllegalArgumentException.
*/
@Test
voidtestIllegalInput() {
assertThrows(IllegalArgumentException.class, () -> CatalanNumbers.catalan(-1));
assertThrows(IllegalArgumentException.class, () -> CatalanNumbers.catalan(-5));
}
}