mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
testing: Enhance ValidParenthesesTest (#6398)
* testing: improve test coverage ValidParenthesesTest * style: fix formatting for checkstyle * style: fix formatting for checkstyle * style: fix import --------- Co-authored-by: Deniz Altunkapan <93663085+DenizAltunkapan@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
334543f54c
commit
0a46b828c2
@@ -1,15 +1,33 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
public class ValidParenthesesTest {
|
||||
|
||||
@ParameterizedTest(name = "Input: \"{0}\" → Expected: {1}")
|
||||
@CsvSource({"'()', true", "'()[]{}', true", "'(]', false", "'{[]}', true", "'([{}])', true", "'([)]', false", "'', true", "'(', false", "')', false"})
|
||||
void testIsValid(String input, boolean expected) {
|
||||
@CsvSource({"'()', true", "'()[]{}', true", "'(]', false", "'{[]}', true", "'([{}])', true", "'([)]', false", "'', true", "'(', false", "')', false", "'{{{{}}}}', true", "'[({})]', true", "'[(])', false", "'[', false", "']', false", "'()()()()', true", "'(()', false", "'())', false",
|
||||
"'{[()()]()}', true"})
|
||||
void
|
||||
testIsValid(String input, boolean expected) {
|
||||
assertEquals(expected, ValidParentheses.isValid(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNullInputThrows() {
|
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> ValidParentheses.isValid(null));
|
||||
assertEquals("Input string cannot be null", ex.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "Input: \"{0}\" → throws IllegalArgumentException")
|
||||
@CsvSource({"'a'", "'()a'", "'[123]'", "'{hello}'", "'( )'", "'\t'", "'\n'", "'@#$%'"})
|
||||
void testInvalidCharactersThrow(String input) {
|
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> ValidParentheses.isValid(input));
|
||||
assertTrue(ex.getMessage().startsWith("Unexpected character"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user