Skip to content

Commit 9505edb

Browse files
author
Samuel Facchinello
committed
add test
1 parent 7d13207 commit 9505edb

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.thealgorithms.others;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.util.Set;
6+
import java.util.stream.Stream;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.Arguments;
9+
import org.junit.jupiter.params.provider.MethodSource;
10+
11+
class StringMatchFiniteAutomataTest {
12+
13+
@ParameterizedTest
14+
@MethodSource("provideTestCases")
15+
void searchPattern(String text, String pattern, Set<Integer> expectedOutput) {
16+
assertEquals(expectedOutput, StringMatchFiniteAutomata.searchPattern(text, pattern));
17+
}
18+
19+
private static Stream<Arguments> provideTestCases() {
20+
return Stream.of(
21+
Arguments.of("abcbcabc", "abc", Set.of(0, 5)), //
22+
Arguments.of("", "abc", Set.of()), //
23+
Arguments.of("abcdefg", "xyz", Set.of()), //
24+
Arguments.of("abcde", "", Set.of(1, 2, 3, 4, 5)), //
25+
Arguments.of("abcabcabc", "abc", Set.of(0, 3, 6)), //
26+
Arguments.of("abcabcabc", "abcabcabc", Set.of(0)), //
27+
Arguments.of("aaabbbaaa", "aaa", Set.of(0, 6)), //
28+
Arguments.of("abcdefg", "efg", Set.of(4))//
29+
);
30+
}
31+
}

0 commit comments

Comments
 (0)