-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathOperationTest.java
More file actions
64 lines (47 loc) · 1.75 KB
/
OperationTest.java
File metadata and controls
64 lines (47 loc) · 1.75 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package calculator;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class OperationTest {
private Operation operation;
@BeforeEach
void setUp() {
operation = null;
}
@Test
void validateMixed() {
String wrongInput = "2/ 3";
assertThatThrownBy(() -> operation = new Operation(wrongInput))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("한 String에 숫자와 연산자가 함께 있거나, ");
}
@Test
void validateOtherSymbols() {
String wrongInput = "( 3 - 4";
assertThatThrownBy(() -> operation = new Operation(wrongInput))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("숫자 연산자 이외의 입력입니다");
}
@Test
void validateFirstIndex() {
String wrongInput = "- 2 + 1";
assertThatThrownBy(() -> operation = new Operation(wrongInput))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("숫자로 시작해야 합니다.");
}
@Test
void validateDuplicate() {
String wrongInput = "2 * / 1 + 3";
assertThatThrownBy(() -> operation = new Operation(wrongInput))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("기호나 숫자가 두 번 연속");
}
@Test
void splitOperation() {
String input = "2 + -3 * 4 / 2";
operation = new Operation(input);
assertThat(operation.getOperands()).isEqualTo(Arrays.asList(2, -3, 4, 2));
assertThat(operation.getOperators()).isEqualTo(Arrays.asList('+', '*', '/'));
}
}