Skip to content

Commit bb9737e

Browse files
committed
Testing the functionality of KnuthMorrisPratt in KnuthMorrisPrattTest
1 parent 525b1ba commit bb9737e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.thealgorithms.strings;
2+
3+
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
4+
5+
import java.util.List;
6+
import java.util.stream.Stream;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.MethodSource;
9+
10+
// Test class for Knuth-Morris-Pratt algorithm
11+
class KnuthMorrisPrattTest {
12+
13+
// Method to provide test data
14+
private static Stream<Object[]> provideTestData() {
15+
return Stream.of(new Object[] {"ababacababaad", "ababa", List.of(0, 6)}, new Object[] {"hello world", "world", List.of(6)}, new Object[] {"aaaaa", "b", List.of()}, new Object[] {"BBCDEFG", "AAB", List.of()}, new Object[] {"ABABDABACD", "ABABC", List.of()});
16+
}
17+
18+
// Parameterized test method for the search function
19+
@ParameterizedTest(name = "{0} and {1} should return {2}")
20+
@MethodSource("provideTestData")
21+
void searchTest(String test, String expected, List<Integer> expectedResult) {
22+
List<Integer> result = KnuthMorrisPratt.search(test, expected);
23+
assertIterableEquals(result, expectedResult);
24+
}
25+
}

0 commit comments

Comments
 (0)