forked from woowacourse-precourse/java-calculator-7
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculationTest.java
More file actions
48 lines (36 loc) · 1.19 KB
/
CalculationTest.java
File metadata and controls
48 lines (36 loc) · 1.19 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
43
44
45
46
47
48
package calculator.calculation;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
class CalculationTest {
private final Calculation calculator = Calculation.getInstance();
@Test
@DisplayName("정상적인 숫자 배열로 계산")
void testCalculateWithValidNumbers() {
// Given
String[] numbers = {"1", "2", "3"};
// When
int result = calculator.calculate(numbers);
// Then
assertEquals(6, result);
}
@Test
@DisplayName("빈 배열 입력 시 0 반환")
void testCalculateWithEmptyArray() {
// Given
String[] numbers = {};
// When
int result = calculator.calculate(numbers);
// Then
assertEquals(0, result);
}
@Test
@DisplayName("숫자가 아닌 값이 포함되었을 때 예외 발생")
void testCalculateWithInvalidNumber() {
// Given
String[] numbers = {"1", "a", "3"};
// When & Then
assertThrows(IllegalArgumentException.class, () -> calculator.calculate(numbers));
}
}