-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCalculatorTest.java
More file actions
53 lines (38 loc) · 1.37 KB
/
CalculatorTest.java
File metadata and controls
53 lines (38 loc) · 1.37 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
package calculator;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
class CalculatorTest {
Calculator calculator = new Calculator();
@Test
void calculate_test_single() {
ArrayList<String> input = new ArrayList<>(List.of("12"));
int result = calculator.calculate(input);
assertThat(result).isEqualTo(12);
}
@Test
void calculate_test_simple() {
ArrayList<String> input = new ArrayList<>(List.of("1", "+", "2"));
int result = calculator.calculate(input);
assertThat(result).isEqualTo(3);
}
@Test
void calculate_test_divide() {
ArrayList<String> input = new ArrayList<>(List.of("4", "/", "2"));
int result = calculator.calculate(input);
assertThat(result).isEqualTo(2);
}
@Test
void calculate_test_complex() {
ArrayList<String> input = new ArrayList<>(List.of("2", "+", "3", "*", "4"));
int result = calculator.calculate(input);
assertThat(result).isEqualTo(20);
}
@Test
void calculate_test_wrong_operator() {
ArrayList<String> input = new ArrayList<>(List.of("1", "&", "2"));
assertThrows(IllegalStateException.class, () -> calculator.calculate(input));
}
}