4
4
import static org .junit .jupiter .api .Assertions .assertThrows ;
5
5
import static org .junit .jupiter .api .Assertions .assertTrue ;
6
6
7
+ import java .util .stream .Stream ;
7
8
import org .junit .jupiter .api .Test ;
8
9
import org .junit .jupiter .params .ParameterizedTest ;
10
+ import org .junit .jupiter .params .provider .Arguments ;
9
11
import org .junit .jupiter .params .provider .CsvSource ;
12
+ import org .junit .jupiter .params .provider .MethodSource ;
10
13
11
14
class DuplicateBracketsTest {
12
15
13
16
@ 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))'" })
15
18
void testInputReturnsFalse (String input ) {
16
19
assertFalse (DuplicateBrackets .check (input ));
17
20
}
18
21
19
22
@ 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)))'" , "'(((())))'" })
21
24
void testInputReturnsTrue (String input ) {
22
25
assertTrue (DuplicateBrackets .check (input ));
23
26
}
@@ -26,4 +29,27 @@ void testInputReturnsTrue(String input) {
26
29
void testInvalidInput () {
27
30
assertThrows (IllegalArgumentException .class , () -> DuplicateBrackets .check (null ));
28
31
}
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
+ }
29
55
}
0 commit comments