test: LongestValidParenthesesTest
(#5416)
* test: LongestValidParenthesesTest * checkstyle: fix formatting --------- Co-authored-by: alxkm <alx@alx.com>
This commit is contained in:
parent
7d1847f51c
commit
203d544668
@ -1,51 +0,0 @@
|
||||
package com.thealgorithms.dynamicprogramming;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class LongestValidParenthesesTest {
|
||||
|
||||
LongestValidParentheses longestValidParentheses = new LongestValidParentheses();
|
||||
|
||||
@Test
|
||||
void shouldReturnZeroWhenSingleOpeningParenthesisIsGiven() {
|
||||
String input = "(";
|
||||
int validLength = longestValidParentheses.getLongestValidParentheses(input);
|
||||
assertEquals(0, validLength);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnZeroWhenSingleClosingParenthesisIsGiven() {
|
||||
String input = ")";
|
||||
int validLength = longestValidParentheses.getLongestValidParentheses(input);
|
||||
assertEquals(0, validLength);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnZeroWhenNullStringIsGiven() {
|
||||
String input = "";
|
||||
int validLength = longestValidParentheses.getLongestValidParentheses(input);
|
||||
assertEquals(0, validLength);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnTwoWhenTwoBalancedParenthesesAreGiven() {
|
||||
String input = "()";
|
||||
int validLength = longestValidParentheses.getLongestValidParentheses(input);
|
||||
assertEquals(2, validLength);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnLengthWhenInputStringIsValid() {
|
||||
String input = "()((()))";
|
||||
int validLength = longestValidParentheses.getLongestValidParentheses(input);
|
||||
assertEquals(8, validLength);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnValidLengthWhenInputStringIsGiven() {
|
||||
String input = "((()((())))";
|
||||
int validLength = longestValidParentheses.getLongestValidParentheses(input);
|
||||
assertEquals(10, validLength);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
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 LongestValidParenthesesTest {
|
||||
|
||||
private static Stream<Arguments> provideTestCases() {
|
||||
return Stream.of(Arguments.of("", 0), Arguments.of("(", 0), Arguments.of(")", 0), Arguments.of("()", 2), Arguments.of("(())", 4), Arguments.of("()()", 4), Arguments.of(")(", 0), Arguments.of("(()", 2), Arguments.of("())(", 2), Arguments.of("(()())", 6), Arguments.of("(((())))", 8),
|
||||
Arguments.of("(()))(()", 4), Arguments.of("()()()(", 6), Arguments.of("(()())()(", 8), Arguments.of("((((((", 0), Arguments.of("))))))", 0), Arguments.of("(()())(", 6), Arguments.of("))()(", 2), Arguments.of("()((()))", 8), Arguments.of("((()((())))", 10));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideTestCases")
|
||||
public void testLongestValidParentheses(String input, int expected) {
|
||||
assertEquals(expected, LongestValidParentheses.getLongestValidParentheses(input));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user