mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-26 05:59:22 +08:00
feat: add recursion subsets (#5503)
This commit is contained in:
@ -0,0 +1,36 @@
|
||||
package com.thealgorithms.Recursion;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class GenerateSubsetsTest {
|
||||
|
||||
@Test
|
||||
void subsetRecursionTestOne() {
|
||||
String str = "abc";
|
||||
String[] expected = new String[] {"abc", "ab", "ac", "a", "bc", "b", "c", ""};
|
||||
|
||||
List<String> ans = GenerateSubsets.subsetRecursion(str);
|
||||
assertArrayEquals(ans.toArray(), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
void subsetRecursionTestTwo() {
|
||||
String str = "cbf";
|
||||
String[] expected = new String[] {"cbf", "cb", "cf", "c", "bf", "b", "f", ""};
|
||||
|
||||
List<String> ans = GenerateSubsets.subsetRecursion(str);
|
||||
assertArrayEquals(ans.toArray(), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
void subsetRecursionTestThree() {
|
||||
String str = "aba";
|
||||
String[] expected = new String[] {"aba", "ab", "aa", "a", "ba", "b", "a", ""};
|
||||
|
||||
List<String> ans = GenerateSubsets.subsetRecursion(str);
|
||||
assertArrayEquals(ans.toArray(), expected);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user