mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
* feat: add Valid Parentheses algorithm using Stack * fix: add missing ValidParentheses.java implementation * fix: remove trailing spaces and add newline at EOF * fix: remove misplaced ValidParentheses.java from root
33 lines
962 B
Java
33 lines
962 B
Java
package com.thealgorithms.stacks;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
class ValidParenthesesTest {
|
|
|
|
@Test
|
|
void testValidParentheses() {
|
|
assertTrue(ValidParentheses.isValid("()"));
|
|
assertTrue(ValidParentheses.isValid("()[]{}"));
|
|
assertTrue(ValidParentheses.isValid("{[]}"));
|
|
assertTrue(ValidParentheses.isValid(""));
|
|
}
|
|
|
|
@Test
|
|
void testInvalidParentheses() {
|
|
assertFalse(ValidParentheses.isValid("(]"));
|
|
assertFalse(ValidParentheses.isValid("([)]"));
|
|
assertFalse(ValidParentheses.isValid("{{{"));
|
|
assertFalse(ValidParentheses.isValid("}"));
|
|
assertFalse(ValidParentheses.isValid("("));
|
|
}
|
|
|
|
@Test
|
|
void testNullAndOddLength() {
|
|
assertFalse(ValidParentheses.isValid(null));
|
|
assertFalse(ValidParentheses.isValid("(()"));
|
|
}
|
|
}
|