- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathArrayCombinationTest.java
40 lines (34 loc) · 2.21 KB
/
ArrayCombinationTest.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
packagecom.thealgorithms.backtracking;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importstaticorg.junit.jupiter.api.Assertions.assertThrows;
importcom.thealgorithms.maths.BinomialCoefficient;
importjava.util.ArrayList;
importjava.util.List;
importjava.util.stream.Stream;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.Arguments;
importorg.junit.jupiter.params.provider.MethodSource;
publicclassArrayCombinationTest {
@ParameterizedTest
@MethodSource("regularInputs")
voidtestCombination(intn, intk, List<List<Integer>> expected) {
assertEquals(expected.size(), BinomialCoefficient.binomialCoefficient(n, k));
assertEquals(expected, ArrayCombination.combination(n, k));
}
@ParameterizedTest
@MethodSource("wrongInputs")
voidtestCombinationThrows(intn, intk) {
assertThrows(IllegalArgumentException.class, () -> ArrayCombination.combination(n, k));
}
privatestaticStream<Arguments> regularInputs() {
returnStream.of(Arguments.of(0, 0, List.of(newArrayList<Integer>())), Arguments.of(1, 0, List.of(newArrayList<Integer>())), Arguments.of(1, 1, List.of(List.of(0))), Arguments.of(3, 0, List.of(newArrayList<Integer>())), Arguments.of(3, 1, List.of(List.of(0), List.of(1), List.of(2))),
Arguments.of(4, 2, List.of(List.of(0, 1), List.of(0, 2), List.of(0, 3), List.of(1, 2), List.of(1, 3), List.of(2, 3))),
Arguments.of(5, 3, List.of(List.of(0, 1, 2), List.of(0, 1, 3), List.of(0, 1, 4), List.of(0, 2, 3), List.of(0, 2, 4), List.of(0, 3, 4), List.of(1, 2, 3), List.of(1, 2, 4), List.of(1, 3, 4), List.of(2, 3, 4))),
Arguments.of(6, 4,
List.of(List.of(0, 1, 2, 3), List.of(0, 1, 2, 4), List.of(0, 1, 2, 5), List.of(0, 1, 3, 4), List.of(0, 1, 3, 5), List.of(0, 1, 4, 5), List.of(0, 2, 3, 4), List.of(0, 2, 3, 5), List.of(0, 2, 4, 5), List.of(0, 3, 4, 5), List.of(1, 2, 3, 4), List.of(1, 2, 3, 5), List.of(1, 2, 4, 5),
List.of(1, 3, 4, 5), List.of(2, 3, 4, 5))));
}
privatestaticStream<Arguments> wrongInputs() {
returnStream.of(Arguments.of(-1, 0), Arguments.of(0, -1), Arguments.of(2, 100), Arguments.of(3, 4));
}
}