- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathRegexMatchingTest.java
43 lines (34 loc) · 1.91 KB
/
RegexMatchingTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
packagecom.thealgorithms.dynamicprogramming;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importjava.util.stream.Stream;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.Arguments;
importorg.junit.jupiter.params.provider.MethodSource;
publicclassRegexMatchingTest {
privaterecordRegexTestCase(Strings, Stringp, booleanexpected) {
}
privatestaticStream<Arguments> provideTestCases() {
returnStream.of(Arguments.of(newRegexTestCase("aa", "*", true)), Arguments.of(newRegexTestCase("aa", "a*", true)), Arguments.of(newRegexTestCase("aa", "a", false)), Arguments.of(newRegexTestCase("cb", "?b", true)), Arguments.of(newRegexTestCase("cb", "?a", false)),
Arguments.of(newRegexTestCase("adceb", "*a*b", true)), Arguments.of(newRegexTestCase("acdcb", "a*c?b", false)), Arguments.of(newRegexTestCase("", "*", true)), Arguments.of(newRegexTestCase("", "", true)));
}
@ParameterizedTest
@MethodSource("provideTestCases")
voidtestRegexRecursionMethod1(RegexTestCasetestCase) {
assertEquals(testCase.expected(), RegexMatching.regexRecursion(testCase.s(), testCase.p()));
}
@ParameterizedTest
@MethodSource("provideTestCases")
voidtestRegexRecursionMethod2(RegexTestCasetestCase) {
assertEquals(testCase.expected(), RegexMatching.regexRecursion(testCase.s(), testCase.p(), 0, 0));
}
@ParameterizedTest
@MethodSource("provideTestCases")
voidtestRegexRecursionMethod3(RegexTestCasetestCase) {
assertEquals(testCase.expected(), RegexMatching.regexRecursion(testCase.s(), testCase.p(), 0, 0, newint[testCase.s().length()][testCase.p().length()]));
}
@ParameterizedTest
@MethodSource("provideTestCases")
voidtestRegexBottomUp(RegexTestCasetestCase) {
assertEquals(testCase.expected(), RegexMatching.regexBU(testCase.s(), testCase.p()));
}
}