-
Notifications
You must be signed in to change notification settings - Fork 906
Expand file tree
/
Copy pathCalculatorTest.java
More file actions
42 lines (37 loc) · 1.52 KB
/
CalculatorTest.java
File metadata and controls
42 lines (37 loc) · 1.52 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
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.*;
public class CalculatorTest {
@DisplayName("정상 입력시 의도대로 계산된 값이 나오는지 테스트")
@Test
void calculateTest(){
StringCalc calculator = new StringCalc(new Formula("5 + 5 * 5 / 25"));
int result = calculator.calc();
assertThat(2).isEqualTo(result);
}
@DisplayName("0 으로 나눌 시 IllegalArgumentException 발생 하는지 테스트")
@Test
void divideZeroTest(){
assertThatIllegalArgumentException().isThrownBy(() -> {
StringCalc calculator = new StringCalc(new Formula("2 + 2 * 10 / 0"));
int result = calculator.calc();
assertThat(2).isEqualTo(result);
});
}
@DisplayName("입력 값이 null 이거나 빈 공백 문자일 경우 IllegalArgumentException 발생 하는지 테스트")
@Test
void inputNullOrEmptyTest(){
assertThatIllegalArgumentException().isThrownBy(() -> {
StringCalc calculator = new StringCalc(new Formula("2 + * 2 / 2"));
int result = calculator.calc();
});
}
@DisplayName("사칙연산 기호가 아닌 경우 IllegalArgumentException throw")
@Test
void checkPermittedOperator(){
assertThatIllegalArgumentException().isThrownBy(() -> {
StringCalc calculator = new StringCalc(new Formula("2 $ 6 * 5 / 4"));
int result = calculator.calc();
});
}
}