Skip to content

Commit 99af777

Browse files
committed
test: 계산기 동작 테스트
1 parent 91a5c98 commit 99af777

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package calculator;
2+
3+
import function.Calculation;
4+
import function.Storage;
5+
import org.junit.jupiter.api.DisplayName;
6+
import org.junit.jupiter.api.Test;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
public class CalculatorTest {
11+
@DisplayName("중위표현식을 후위표현식으로 변환한다.")
12+
@Test
13+
void checkPostfixExpression() {
14+
final String infixExp = "3 + 5 * 2 / ( 7 - 2 )";
15+
final String postfixExp = "3 5 2 * 7 2 - / + ";
16+
17+
final Calculation calculation = new Calculation();
18+
assertThat(calculation.convertPostfix(infixExp)).isEqualTo(postfixExp);
19+
}
20+
21+
@DisplayName("후위표현식을 계산한 결과를 출력한다.")
22+
@Test
23+
void checkResult() {
24+
final String postfixExp = "3 5 2 * 7 2 - / +";
25+
final double result = 5;
26+
27+
final Calculation calculation = new Calculation();
28+
assertThat(calculation.calculatePostfix(postfixExp)).isEqualTo(result);
29+
}
30+
31+
@DisplayName("계산한 결과가 저장된다.")
32+
@Test
33+
void checkStore() {
34+
final String exp1 = "2 + 3 = 5";
35+
36+
final Storage storage = new Storage();
37+
storage.store(exp1);
38+
39+
assertThat(storage.print().replace("\n", "")).isEqualTo(exp1);
40+
}
41+
}

0 commit comments

Comments
 (0)