-
Notifications
You must be signed in to change notification settings - Fork 19.7k
/
Copy pathParenthesesGeneratorTest.java
33 lines (27 loc) · 1.46 KB
/
ParenthesesGeneratorTest.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
package com.thealgorithms.backtracking;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
public class ParenthesesGeneratorTest {
@ParameterizedTest
@MethodSource("regularInputStream")
void regularInputTests(int input, List<String> expected) {
assertEquals(expected, ParenthesesGenerator.generateParentheses(input));
}
@ParameterizedTest
@MethodSource("negativeInputStream")
void throwsForNegativeInputTests(int input) {
assertThrows(IllegalArgumentException.class, () -> ParenthesesGenerator.generateParentheses(input));
}
private static Stream<Arguments> regularInputStream() {
return Stream.of(Arguments.of(0, List.of("")), Arguments.of(1, List.of("()")), Arguments.of(2, List.of("(())", "()()")), Arguments.of(3, List.of("((()))", "(()())", "(())()", "()(())", "()()()")),
Arguments.of(4, List.of("(((())))", "((()()))", "((())())", "((()))()", "(()(()))", "(()()())", "(()())()", "(())(())", "(())()()", "()((()))", "()(()())", "()(())()", "()()(())", "()()()()")));
}
private static Stream<Arguments> negativeInputStream() {
return Stream.of(Arguments.of(-1), Arguments.of(-5), Arguments.of(-10));
}
}