|
4 | 4 | import org.junit.jupiter.params.ParameterizedTest;
|
5 | 5 | import org.junit.jupiter.params.provider.Arguments;
|
6 | 6 | import org.junit.jupiter.params.provider.MethodSource;
|
| 7 | +import org.junit.jupiter.params.provider.ValueSource; |
| 8 | +import org.programmers.java.validator.Validator; |
7 | 9 |
|
8 | 10 | import java.util.Arrays;
|
9 | 11 | import java.util.List;
|
10 | 12 | import java.util.stream.Stream;
|
11 | 13 |
|
12 |
| -import static org.junit.jupiter.api.Assertions.assertEquals; |
| 14 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
13 | 15 |
|
14 | 16 | public class ValidaionTest {
|
15 |
| - FormulaSplitValidator formulaSplitValidator = new FormulaSplitValidator(); |
16 |
| - FormulaCountValidator formulaCountValidator = new FormulaCountValidator(); |
17 | 17 |
|
18 | 18 | @ParameterizedTest
|
19 |
| - @DisplayName("연산식 검증: 연산식 분해 검증") |
20 |
| - @MethodSource("makeFormulaAndList") |
21 |
| - void formulaSplitValidation(String input, List<String> formula){ |
22 |
| - // when |
23 |
| - List<String> formulaList = formulaSplitValidator.validate(input); |
24 |
| - |
25 |
| - // then |
26 |
| - assertEquals(formula, formulaList); |
27 |
| - } |
28 |
| - |
29 |
| - static Stream<Arguments> makeFormulaAndList(){ |
30 |
| - return Stream.of( |
31 |
| - Arguments.of("10 + 4 / 20 * 3 - 2", Arrays.asList("10", "+", "4", "/", "20", "*", "3", "-", "2")), |
32 |
| - Arguments.of("5 - 2 * 20 + 3 / 2", Arrays.asList("5","-","2","*","20","+","3","/","2")), |
33 |
| - Arguments.of("7 * 2 - 3 / 3 + 2", Arrays.asList("7","*","2","-","3","/","3","+","2")) |
34 |
| - ); |
| 19 | + @DisplayName("연산자 혹은 피연산자가 아닌 것이 들어오면 예외가 발생한다.") |
| 20 | + @ValueSource(strings = {"10 + 4 / 20 * 3 - ㄱ", "# + 3 - 11", "****"}) |
| 21 | + void formulaSplitValidation(String input){ |
| 22 | + assertThrows(IllegalArgumentException.class, () -> Validator.formulaSplitValidate(input)); |
35 | 23 | }
|
36 | 24 |
|
37 | 25 | @ParameterizedTest
|
38 |
| - @DisplayName("연산식 검증: 연산자와 피연산자의 전체 개수 검증 및 위치 검증") |
| 26 | + @DisplayName("연산자와 피연산자 수, 리스트 전체 개수, 위치가 맞지 않으면 예외가 발상핸다.") |
39 | 27 | @MethodSource("makeFormulaList")
|
40 | 28 | void checkFormulaValidation(List<String> formulaList){
|
41 |
| - // when |
42 |
| - Boolean checkedFormulaValidation = formulaCountValidator.validate(formulaList); |
43 |
| - |
44 |
| - // then |
45 |
| - assertEquals(checkedFormulaValidation, true); |
| 29 | + assertThrows(IllegalArgumentException.class, () -> Validator.formulaCountValidate(formulaList)); |
46 | 30 | }
|
47 | 31 |
|
48 | 32 | static Stream<Arguments> makeFormulaList(){
|
49 | 33 | return Stream.of(
|
50 |
| - Arguments.of(Arrays.asList("10", "+", "4", "/", "20", "*", "3", "-", "2")), |
51 |
| - Arguments.of(Arrays.asList("5","-","2","*","20","+","3","/","2")), |
52 |
| - Arguments.of(Arrays.asList("7","*","2","-","3","/","3","+","2")) |
| 34 | + Arguments.of(Arrays.asList("10", "+", "4", "/", "20", "*", "3", "-")), |
| 35 | + Arguments.of(Arrays.asList("5","2","*","20","+","3","/","2")), |
| 36 | + Arguments.of(Arrays.asList("7","*","2","-","3","/","3","+")) |
53 | 37 | );
|
54 | 38 | }
|
55 | 39 | }
|
0 commit comments