Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21.3k
Expand file tree
/
Copy pathCombinationTest.java
More file actions
Latest commit
51 lines (43 loc) · 1.69 KB
/
Copy pathCombinationTest.java
File metadata and controls
51 lines (43 loc) · 1.69 KB
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
44
45
46
47
48
49
50
51
packagecom.thealgorithms.backtracking;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importstaticorg.junit.jupiter.api.Assertions.assertNotNull;
importstaticorg.junit.jupiter.api.Assertions.assertThrows;
importstaticorg.junit.jupiter.api.Assertions.assertTrue;
importjava.util.List;
importjava.util.Set;
importjava.util.TreeSet;
importorg.junit.jupiter.api.Test;
publicclassCombinationTest {
@Test
voidtestNegativeElement() {
Integer[] array = {1, 2};
assertThrows(IllegalArgumentException.class, () -> { Combination.combination(array, -1); });
}
@Test
voidtestNoElement() {
List<TreeSet<Integer>> result = Combination.combination(newInteger[] {1, 2}, 0);
assertNotNull(result);
assertEquals(0, result.size());
}
@Test
voidtestLengthOne() {
List<TreeSet<Integer>> result = Combination.combination(newInteger[] {1, 2}, 1);
assertEquals(1, result.get(0).iterator().next());
assertEquals(2, result.get(1).iterator().next());
}
@Test
voidtestLengthTwo() {
List<TreeSet<Integer>> result = Combination.combination(newInteger[] {1, 2}, 2);
Integer[] arr = result.get(0).toArray(newInteger[2]);
assertEquals(1, arr[0]);
assertEquals(2, arr[1]);
}
@Test
voidtestCombinationsWithStrings() {
List<TreeSet<String>> result = Combination.combination(newString[] {"a", "b", "c"}, 2);
assertEquals(3, result.size());
assertTrue(result.contains(newTreeSet<>(Set.of("a", "b"))));
assertTrue(result.contains(newTreeSet<>(Set.of("a", "c"))));
assertTrue(result.contains(newTreeSet<>(Set.of("b", "c"))));
}
}