Add LongestValidParenthesesTest (#3612)
This commit is contained in:
parent
bf03d16303
commit
8d4b048cb3
@ -43,19 +43,4 @@ public class LongestValidParentheses {
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
while (true) {
|
||||
String str = sc.nextLine();
|
||||
if ("quit".equals(str)) {
|
||||
break;
|
||||
}
|
||||
|
||||
System.out.println("Len is: " + getLongestValidParentheses(str));
|
||||
}
|
||||
|
||||
sc.close();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user