forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuplicateBracketsTest.java
More file actions
55 lines (45 loc) · 2.06 KB
/
DuplicateBracketsTest.java
File metadata and controls
55 lines (45 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.thealgorithms.stacks;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
class DuplicateBracketsTest {
@ParameterizedTest
@CsvSource({"'((a + b) + (c + d))'", "'(a + b)'", "'a + b'", "'('", "''", "'a + (b * c) - d'", "'(x + y) * (z)'", "'(a + (b - c))'"})
void testInputReturnsFalse(String input) {
assertFalse(DuplicateBrackets.check(input));
}
@ParameterizedTest
@CsvSource({"'(a + b) + ((c + d))'", "'((a + b))'", "'((((a + b)))))'", "'((x))'", "'((a + (b)))'", "'(a + ((b)))'", "'(((a)))'", "'(((())))'"})
void testInputReturnsTrue(String input) {
assertTrue(DuplicateBrackets.check(input));
}
@Test
void testInvalidInput() {
assertThrows(IllegalArgumentException.class, () -> DuplicateBrackets.check(null));
}
@ParameterizedTest(name = "Should be true: \"{0}\"")
@MethodSource("provideInputsThatShouldReturnTrue")
void testDuplicateBracketsTrueCases(String input) {
assertTrue(DuplicateBrackets.check(input));
}
static Stream<Arguments> provideInputsThatShouldReturnTrue() {
return Stream.of(Arguments.of("()"), Arguments.of("(( ))"));
}
@ParameterizedTest(name = "Should be false: \"{0}\"")
@MethodSource("provideInputsThatShouldReturnFalse")
void testDuplicateBracketsFalseCases(String input) {
assertFalse(DuplicateBrackets.check(input));
}
static Stream<Arguments> provideInputsThatShouldReturnFalse() {
return Stream.of(Arguments.of("( )"), // whitespace inside brackets
Arguments.of("abc + def"), // no brackets
Arguments.of("(a + (b * c)) - (d / e)") // complex, but no duplicates
);
}
}