mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 22:43:30 +08:00
refactor: BalancedBrackets
(#5391)
This commit is contained in:
@ -0,0 +1,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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user