Skip to content

Commit d14e8a6

Browse files
testing: improve test coverage DuplicateBracketsTest (#6396)
* testing: improve test coverage DuplicateBracketsTest * style: fix formatting checkstyle * style: fix formatting checkstyle --------- Co-authored-by: Deniz Altunkapan <[email protected]>
1 parent 76aea42 commit d14e8a6

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/test/java/com/thealgorithms/stacks/DuplicateBracketsTest.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44
import static org.junit.jupiter.api.Assertions.assertThrows;
55
import static org.junit.jupiter.api.Assertions.assertTrue;
66

7+
import java.util.stream.Stream;
78
import org.junit.jupiter.api.Test;
89
import org.junit.jupiter.params.ParameterizedTest;
10+
import org.junit.jupiter.params.provider.Arguments;
911
import org.junit.jupiter.params.provider.CsvSource;
12+
import org.junit.jupiter.params.provider.MethodSource;
1013

1114
class DuplicateBracketsTest {
1215

1316
@ParameterizedTest
14-
@CsvSource({"'((a + b) + (c + d))'", "'(a + b)'", "'a + b'", "'('", "''"})
17+
@CsvSource({"'((a + b) + (c + d))'", "'(a + b)'", "'a + b'", "'('", "''", "'a + (b * c) - d'", "'(x + y) * (z)'", "'(a + (b - c))'"})
1518
void testInputReturnsFalse(String input) {
1619
assertFalse(DuplicateBrackets.check(input));
1720
}
1821

1922
@ParameterizedTest
20-
@CsvSource({"'(a + b) + ((c + d))'", "'((a + b))'", "'((((a + b)))))'"})
23+
@CsvSource({"'(a + b) + ((c + d))'", "'((a + b))'", "'((((a + b)))))'", "'((x))'", "'((a + (b)))'", "'(a + ((b)))'", "'(((a)))'", "'(((())))'"})
2124
void testInputReturnsTrue(String input) {
2225
assertTrue(DuplicateBrackets.check(input));
2326
}
@@ -26,4 +29,27 @@ void testInputReturnsTrue(String input) {
2629
void testInvalidInput() {
2730
assertThrows(IllegalArgumentException.class, () -> DuplicateBrackets.check(null));
2831
}
32+
33+
@ParameterizedTest(name = "Should be true: \"{0}\"")
34+
@MethodSource("provideInputsThatShouldReturnTrue")
35+
void testDuplicateBracketsTrueCases(String input) {
36+
assertTrue(DuplicateBrackets.check(input));
37+
}
38+
39+
static Stream<Arguments> provideInputsThatShouldReturnTrue() {
40+
return Stream.of(Arguments.of("()"), Arguments.of("(( ))"));
41+
}
42+
43+
@ParameterizedTest(name = "Should be false: \"{0}\"")
44+
@MethodSource("provideInputsThatShouldReturnFalse")
45+
void testDuplicateBracketsFalseCases(String input) {
46+
assertFalse(DuplicateBrackets.check(input));
47+
}
48+
49+
static Stream<Arguments> provideInputsThatShouldReturnFalse() {
50+
return Stream.of(Arguments.of("( )"), // whitespace inside brackets
51+
Arguments.of("abc + def"), // no brackets
52+
Arguments.of("(a + (b * c)) - (d / e)") // complex, but no duplicates
53+
);
54+
}
2955
}

0 commit comments

Comments
 (0)