44import static org .junit .jupiter .api .Assertions .assertThrows ;
55import static org .junit .jupiter .api .Assertions .assertTrue ;
66
7+ import java .util .stream .Stream ;
78import org .junit .jupiter .api .Test ;
89import org .junit .jupiter .params .ParameterizedTest ;
10+ import org .junit .jupiter .params .provider .Arguments ;
911import org .junit .jupiter .params .provider .CsvSource ;
12+ import org .junit .jupiter .params .provider .MethodSource ;
1013
1114class 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