test: RegexMatchingTest (#5403)

* test: RegexMatchingTest

* checkstyle: fix formatting

---------

Co-authored-by: alxkm <alx@alx.com>
Co-authored-by: Andrii Siriak <siryaka@gmail.com>
This commit is contained in:
Alex Klymenko
2024-08-26 16:22:39 +02:00
committed by GitHub
parent 4374a50fd7
commit 7674a84f5b
2 changed files with 99 additions and 23 deletions

View File

@ -0,0 +1,43 @@
package com.thealgorithms.dynamicprogramming;
import static org.junit.jupiter.api.Assertions.assertEquals;
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;
public class RegexMatchingTest {
private record RegexTestCase(String s, String p, boolean expected) {
}
private static Stream<Arguments> provideTestCases() {
return Stream.of(Arguments.of(new RegexTestCase("aa", "*", true)), Arguments.of(new RegexTestCase("aa", "a*", true)), Arguments.of(new RegexTestCase("aa", "a", false)), Arguments.of(new RegexTestCase("cb", "?b", true)), Arguments.of(new RegexTestCase("cb", "?a", false)),
Arguments.of(new RegexTestCase("adceb", "*a*b", true)), Arguments.of(new RegexTestCase("acdcb", "a*c?b", false)), Arguments.of(new RegexTestCase("", "*", true)), Arguments.of(new RegexTestCase("", "", true)));
}
@ParameterizedTest
@MethodSource("provideTestCases")
void testRegexRecursionMethod1(RegexTestCase testCase) {
assertEquals(testCase.expected(), RegexMatching.regexRecursion(testCase.s(), testCase.p()));
}
@ParameterizedTest
@MethodSource("provideTestCases")
void testRegexRecursionMethod2(RegexTestCase testCase) {
assertEquals(testCase.expected(), RegexMatching.regexRecursion(testCase.s(), testCase.p(), 0, 0));
}
@ParameterizedTest
@MethodSource("provideTestCases")
void testRegexRecursionMethod3(RegexTestCase testCase) {
assertEquals(testCase.expected(), RegexMatching.regexRecursion(testCase.s(), testCase.p(), 0, 0, new int[testCase.s().length()][testCase.p().length()]));
}
@ParameterizedTest
@MethodSource("provideTestCases")
void testRegexBottomUp(RegexTestCase testCase) {
assertEquals(testCase.expected(), RegexMatching.regexBU(testCase.s(), testCase.p()));
}
}