- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathGenerateSubsetsTest.java
53 lines (44 loc) · 1.64 KB
/
GenerateSubsetsTest.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
44
45
46
47
48
49
50
51
52
53
packagecom.thealgorithms.bitmanipulation;
importstaticjava.util.Collections.singletonList;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importjava.util.ArrayList;
importjava.util.Arrays;
importjava.util.List;
importorg.junit.jupiter.api.Test;
classGenerateSubsetsTest {
@Test
voidtestGenerateSubsetsWithTwoElements() {
int[] set = {1, 2};
List<List<Integer>> expected = newArrayList<>();
expected.add(newArrayList<>());
expected.add(singletonList(1));
expected.add(singletonList(2));
expected.add(Arrays.asList(1, 2));
List<List<Integer>> result = GenerateSubsets.generateSubsets(set);
assertEquals(expected, result);
}
@Test
voidtestGenerateSubsetsWithOneElement() {
int[] set = {3};
List<List<Integer>> expected = newArrayList<>();
expected.add(newArrayList<>());
expected.add(singletonList(3));
List<List<Integer>> result = GenerateSubsets.generateSubsets(set);
assertEquals(expected, result);
}
@Test
voidtestGenerateSubsetsWithThreeElements() {
int[] set = {4, 5, 6};
List<List<Integer>> expected = newArrayList<>();
expected.add(newArrayList<>());
expected.add(singletonList(4));
expected.add(singletonList(5));
expected.add(Arrays.asList(4, 5));
expected.add(singletonList(6));
expected.add(Arrays.asList(4, 6));
expected.add(Arrays.asList(5, 6));
expected.add(Arrays.asList(4, 5, 6));
List<List<Integer>> result = GenerateSubsets.generateSubsets(set);
assertEquals(expected, result);
}
}