refactor: ReturnSubsequence (#5408)

* refactor: ReturnSubsequence

* checkstyle: fix formatting

* checkstyle: fix formatting

---------

Co-authored-by: alxkm <alx@alx.com>
This commit is contained in:
Alex Klymenko
2024-08-27 13:12:49 +02:00
committed by GitHub
parent 49d1c84cb7
commit fc5a70edc9
2 changed files with 46 additions and 32 deletions

View File

@ -0,0 +1,23 @@
package com.thealgorithms.others;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class ReturnSubsequenceTest {
@ParameterizedTest
@MethodSource("provideTestCases")
void testSubsequences(String input, String[] expected) {
String[] actual = ReturnSubsequence.getSubsequences(input);
assertArrayEquals(expected, actual);
}
static Stream<Arguments> provideTestCases() {
return Stream.of(Arguments.of("", new String[] {""}), Arguments.of("a", new String[] {"", "a"}), Arguments.of("ab", new String[] {"", "b", "a", "ab"}), Arguments.of("abc", new String[] {"", "c", "b", "bc", "a", "ac", "ab", "abc"}),
Arguments.of("aab", new String[] {"", "b", "a", "ab", "a", "ab", "aa", "aab"}));
}
}