forked from risetarnished/coding-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AllSubsetsITest.java
78 lines (67 loc) · 2.19 KB
/
AllSubsetsITest.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package H.DFS.I.Medium.AllSubsetsI;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
class AllSubsetsITest {
private static AllSubsetsI allSubsets;
private String set;
@BeforeAll
static void setInstance() {
allSubsets = new AllSubsetsI();
}
@BeforeEach
void setUp() {
set = null;
}
@AfterEach
void tearDown() {
}
@Test
void testNull() {
assertEquals(new ArrayList<>(), allSubsets.subSets(set));
}
@Test
void testEmpty() {
set = "";
assertEquals(new ArrayList<>(Collections.singletonList("")), allSubsets.subSets(set));
}
@Test
void testOne() {
// abc
set = "abc";
List<String> result = allSubsets.subSets(set);
// To come up with this expected result requires a bit of brain function
// It may be easier if we just sort them since the order does not matter
List<String> expected = new ArrayList<>(Arrays.asList(
"abc", "ab", "ac", "a", "bc", "b", "c", ""
));
Collections.sort(result);
Collections.sort(expected);
System.out.println("Test input: " + set);
System.out.println("Expected all subsets: " + expected);
System.out.println("Actual all subsets: " + result);
assertEquals(expected, result);
}
@Test
void testTwo() {
// qwer
set = "qwer";
List<String> result = allSubsets.subSets(set);
List<String> expected = new ArrayList<>(Arrays.asList(
"qwer", "qwe", "qwr", "qer", "qw", "qe", "qr", "q",
"wer", "we", "wr", "w", "er", "e", "r", ""
));
Collections.sort(result);
Collections.sort(expected);
System.out.println("Test input: " + set);
System.out.println("Expected all subsets: " + expected);
System.out.println("Actural all subsets: " + result);
assertEquals(expected, result);
}
}