Files
Java/src/test/java/com/thealgorithms/recursion/GenerateSubsetsTest.java
Oleksandr Klymenko 78b62191ab 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>
2025-07-22 18:49:37 +02:00

41 lines
1.2 KiB
Java

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);
}
}