|
1 | 1 | package com.thealgorithms.recursion; |
2 | 2 |
|
3 | | -import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
| 3 | +import static org.junit.jupiter.api.Assertions.assertIterableEquals; |
4 | 4 |
|
| 5 | +import java.util.Arrays; |
5 | 6 | import java.util.List; |
| 7 | +import org.junit.jupiter.api.DisplayName; |
6 | 8 | import org.junit.jupiter.api.Test; |
7 | 9 |
|
8 | 10 | public final class GenerateSubsetsTest { |
9 | 11 |
|
10 | 12 | @Test |
11 | | - void subsetRecursionTestOne() { |
12 | | - String str = "abc"; |
13 | | - String[] expected = new String[] {"abc", "ab", "ac", "a", "bc", "b", "c", ""}; |
14 | | - |
15 | | - List<String> ans = GenerateSubsets.subsetRecursion(str); |
16 | | - assertArrayEquals(ans.toArray(), expected); |
| 13 | + @DisplayName("Subsets of 'abc'") |
| 14 | + void testSubsetsOfABC() { |
| 15 | + assertSubsets("abc", Arrays.asList("abc", "ab", "ac", "a", "bc", "b", "c", "")); |
17 | 16 | } |
18 | 17 |
|
19 | 18 | @Test |
20 | | - void subsetRecursionTestTwo() { |
21 | | - String str = "cbf"; |
22 | | - String[] expected = new String[] {"cbf", "cb", "cf", "c", "bf", "b", "f", ""}; |
| 19 | + @DisplayName("Subsets of 'cbf'") |
| 20 | + void testSubsetsOfCBF() { |
| 21 | + assertSubsets("cbf", Arrays.asList("cbf", "cb", "cf", "c", "bf", "b", "f", "")); |
| 22 | + } |
23 | 23 |
|
24 | | - List<String> ans = GenerateSubsets.subsetRecursion(str); |
25 | | - assertArrayEquals(ans.toArray(), expected); |
| 24 | + @Test |
| 25 | + @DisplayName("Subsets of 'aba' with duplicates") |
| 26 | + void testSubsetsWithDuplicateChars() { |
| 27 | + assertSubsets("aba", Arrays.asList("aba", "ab", "aa", "a", "ba", "b", "a", "")); |
26 | 28 | } |
27 | 29 |
|
28 | 30 | @Test |
29 | | - void subsetRecursionTestThree() { |
30 | | - String str = "aba"; |
31 | | - String[] expected = new String[] {"aba", "ab", "aa", "a", "ba", "b", "a", ""}; |
| 31 | + @DisplayName("Subsets of empty string") |
| 32 | + void testEmptyInput() { |
| 33 | + assertSubsets("", List.of("")); |
| 34 | + } |
32 | 35 |
|
33 | | - List<String> ans = GenerateSubsets.subsetRecursion(str); |
34 | | - assertArrayEquals(ans.toArray(), expected); |
| 36 | + private void assertSubsets(String input, List<String> expected) { |
| 37 | + List<String> actual = GenerateSubsets.subsetRecursion(input); |
| 38 | + assertIterableEquals(expected, actual, "Subsets do not match for input: " + input); |
35 | 39 | } |
36 | 40 | } |
0 commit comments