-
Notifications
You must be signed in to change notification settings - Fork 19.7k
/
Copy pathBalancedBracketsTest.java
36 lines (29 loc) · 1.41 KB
/
BalancedBracketsTest.java
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
package com.thealgorithms.stacks;
import static org.junit.jupiter.api.Assertions.assertEquals;
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 org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
class BalancedBracketsTest {
@ParameterizedTest
@CsvSource({"(, )", "[, ]", "{, }", "<, >"})
void testIsPairedTrue(char opening, char closing) {
assertTrue(BalancedBrackets.isPaired(opening, closing));
}
@ParameterizedTest
@CsvSource({"(, ]", "[, )", "{, >", "<, )", "a, b", "!, @"})
void testIsPairedFalse(char opening, char closing) {
assertFalse(BalancedBrackets.isPaired(opening, closing));
}
@ParameterizedTest
@CsvSource({"'[()]{}{[()()]()}', true", "'()', true", "'[]', true", "'{}', true", "'<>', true", "'[{<>}]', true", "'', true", "'[(])', false", "'([)]', false", "'{[<]>}', false", "'[', false", "')', false", "'[{', false", "']', false", "'[a+b]', false", "'a+b', false"})
void testIsBalanced(String input, boolean expected) {
assertEquals(expected, BalancedBrackets.isBalanced(input));
}
@Test
void testIsBalancedNull() {
assertThrows(IllegalArgumentException.class, () -> BalancedBrackets.isBalanced(null));
}
}