Skip to content

Commit 78b6219

Browse files
testing: improving GenerateSubsetsTest (#6412)
* testing: improving GenerateSubsetsTest * testing: change List to more common Iterable --------- Co-authored-by: Deniz Altunkapan <93663085+DenizAltunkapan@users.noreply.github.com>
1 parent 9a46339 commit 78b6219

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
11
package com.thealgorithms.recursion;
22

3-
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
3+
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
44

5+
import java.util.Arrays;
56
import java.util.List;
7+
import org.junit.jupiter.api.DisplayName;
68
import org.junit.jupiter.api.Test;
79

810
public final class GenerateSubsetsTest {
911

1012
@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", ""));
1716
}
1817

1918
@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+
}
2323

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", ""));
2628
}
2729

2830
@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+
}
3235

33-
List<String> ans = GenerateSubsets.subsetRecursion(str);
34-
assertArrayEquals(ans.toArray(), expected);
36+
private void assertSubsets(String input, Iterable<String> expected) {
37+
List<String> actual = GenerateSubsets.subsetRecursion(input);
38+
assertIterableEquals(expected, actual, "Subsets do not match for input: " + input);
3539
}
3640
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy