Skip to content

Commit 0a46b82

Browse files
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>
1 parent 334543f commit 0a46b82

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
package com.thealgorithms.strings;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
46

7+
import org.junit.jupiter.api.Test;
58
import org.junit.jupiter.params.ParameterizedTest;
69
import org.junit.jupiter.params.provider.CsvSource;
710

811
public class ValidParenthesesTest {
912

1013
@ParameterizedTest(name = "Input: \"{0}\" → Expected: {1}")
11-
@CsvSource({"'()', true", "'()[]{}', true", "'(]', false", "'{[]}', true", "'([{}])', true", "'([)]', false", "'', true", "'(', false", "')', false"})
12-
void testIsValid(String input, boolean expected) {
14+
@CsvSource({"'()', true", "'()[]{}', true", "'(]', false", "'{[]}', true", "'([{}])', true", "'([)]', false", "'', true", "'(', false", "')', false", "'{{{{}}}}', true", "'[({})]', true", "'[(])', false", "'[', false", "']', false", "'()()()()', true", "'(()', false", "'())', false",
15+
"'{[()()]()}', true"})
16+
void
17+
testIsValid(String input, boolean expected) {
1318
assertEquals(expected, ValidParentheses.isValid(input));
1419
}
20+
21+
@Test
22+
void testNullInputThrows() {
23+
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> ValidParentheses.isValid(null));
24+
assertEquals("Input string cannot be null", ex.getMessage());
25+
}
26+
27+
@ParameterizedTest(name = "Input: \"{0}\" → throws IllegalArgumentException")
28+
@CsvSource({"'a'", "'()a'", "'[123]'", "'{hello}'", "'( )'", "'\t'", "'\n'", "'@#$%'"})
29+
void testInvalidCharactersThrow(String input) {
30+
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> ValidParentheses.isValid(input));
31+
assertTrue(ex.getMessage().startsWith("Unexpected character"));
32+
}
1533
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy