forked from next-step/java-calculator-unit-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringCalculatorTest.java
More file actions
46 lines (36 loc) · 1.27 KB
/
StringCalculatorTest.java
File metadata and controls
46 lines (36 loc) · 1.27 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
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class StringCalculatorTest {
private final StringCalculator calculator = new StringCalculator();
@Test
public void testEmptyString() {
assertEquals(0, calculator.add(""));
}
@Test
public void testNumbers() {
assertEquals(3, calculator.add("1,2"));
assertEquals(7, calculator.add("3:4"));
assertEquals(6, calculator.add("1,2,3"));
assertEquals(10, calculator.add("4:2:4"));
assertEquals(15, calculator.add("1,2:3,4,5"));
}
@Test
public void testNegativeNumber() {
RuntimeException exception = assertThrows(RuntimeException.class, () -> {
calculator.add("1,-2");
});
assertEquals("음수가 포함되어 있습니다.", exception.getMessage());
}
@Test
public void testInvalidString() {
RuntimeException exception = assertThrows(RuntimeException.class, () -> {
calculator.add("1,a");
});
assertEquals("잘못된 입력입니다.", exception.getMessage());
}
@Test
public void testMixedDelimiters() {
assertEquals(10, calculator.add("1,2:3,4"));
assertEquals(15, calculator.add("1,2:3,4,5"));
}
}