forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateSubsetsTest.java
More file actions
40 lines (32 loc) · 1.17 KB
/
GenerateSubsetsTest.java
File metadata and controls
40 lines (32 loc) · 1.17 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
package com.thealgorithms.recursion;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public final class GenerateSubsetsTest {
@Test
@DisplayName("Subsets of 'abc'")
void testSubsetsOfABC() {
assertSubsets("abc", Arrays.asList("abc", "ab", "ac", "a", "bc", "b", "c", ""));
}
@Test
@DisplayName("Subsets of 'cbf'")
void testSubsetsOfCBF() {
assertSubsets("cbf", Arrays.asList("cbf", "cb", "cf", "c", "bf", "b", "f", ""));
}
@Test
@DisplayName("Subsets of 'aba' with duplicates")
void testSubsetsWithDuplicateChars() {
assertSubsets("aba", Arrays.asList("aba", "ab", "aa", "a", "ba", "b", "a", ""));
}
@Test
@DisplayName("Subsets of empty string")
void testEmptyInput() {
assertSubsets("", List.of(""));
}
private void assertSubsets(String input, Iterable<String> expected) {
List<String> actual = GenerateSubsets.subsetRecursion(input);
assertIterableEquals(expected, actual, "Subsets do not match for input: " + input);
}
}