-
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
package com.thealgorithms.bitmanipulation;
import static java.util.Collections.singletonList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
class GenerateSubsetsTest {
@Test
void testGenerateSubsetsWithTwoElements() {
int[] set = {1, 2};
List<List<Integer>> expected = new ArrayList<>();
expected.add(new ArrayList<>());
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
void testGenerateSubsetsWithOneElement() {
int[] set = {3};
List<List<Integer>> expected = new ArrayList<>();
expected.add(new ArrayList<>());
expected.add(singletonList(3));
List<List<Integer>> result = GenerateSubsets.generateSubsets(set);
assertEquals(expected, result);
}
@Test
void testGenerateSubsetsWithThreeElements() {
int[] set = {4, 5, 6};
List<List<Integer>> expected = new ArrayList<>();
expected.add(new ArrayList<>());
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);
}
}