Skip to content

Commit ada8928

Browse files
committed
test: 중위 표기법을 후위 표기법으로 변경하는 클래스의 테스트 코드 작성
1 parent fda41b6 commit ada8928

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package stack;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.DisplayName;
7+
import org.junit.jupiter.api.Test;
8+
9+
class InfixToPostfixTest {
10+
11+
InfixToPostfix infixToPostfix;
12+
13+
@BeforeEach
14+
void setUp() {
15+
infixToPostfix = new InfixToPostfix();
16+
}
17+
18+
@Test
19+
@DisplayName("입력된 정보를 배열로 만드는지 테스트")
20+
void 입력된_정보를_배열로_만드는지_테스트() {
21+
String input = "1 + 2 * 3";
22+
char[] expected = {'1', '+', '2', '*', '3'};
23+
char[] actual = infixToPostfix.convertInputToCharArray(input);
24+
25+
assertThat(actual).isNotEmpty().hasSameSizeAs(expected).containsExactly(expected);
26+
}
27+
28+
@Test
29+
@DisplayName("중위 표기법 배열을 후위 표기법으로 바꾸는 함수 테스트1")
30+
void 중위_표기법_배열을_후위_표기법으로_바꾸는_함수_테스트1() {
31+
char[] input = {'1', '+', '2', '*', '3'}; // 123*+
32+
char[] expected = {'1', '2', '3', '*', '+'};
33+
char[] actual = infixToPostfix.convertInfixToPostfix(input);
34+
35+
assertThat(actual).isNotEmpty().hasSameSizeAs(expected).containsExactly(expected);
36+
}
37+
38+
@Test
39+
@DisplayName("중위 표기법 배열을 후위 표기법으로 바꾸는 함수 테스트2")
40+
void 중위_표기법_배열을_후위_표기법으로_바꾸는_함수_테스트2() {
41+
char[] input = {'(', '1', '*', '2', '+', '3', ')', '/', '4'}; // 12*3+4/
42+
char[] expected = {'1', '2', '*', '3', '+', '4', '/'};
43+
char[] actual = infixToPostfix.convertInfixToPostfix(input);
44+
45+
assertThat(actual).isNotEmpty().hasSameSizeAs(expected).containsExactly(expected);
46+
}
47+
48+
@Test
49+
@DisplayName("연산자의 연산 우선순위 정보를 반환하는 함수테스트")
50+
void 연산자의_연산_우선순위_정보를_반환하는_함수_테스트() {
51+
char multiplicationSign = '*';
52+
char divisionSign = '/';
53+
char plusSign = '+';
54+
char minusSign = '-';
55+
char openingParenthesis = '(';
56+
char noSign = ')';
57+
58+
assertThat(infixToPostfix.getOperatorPriority(multiplicationSign))
59+
.isEqualTo(OperatorPriority.TOP);
60+
assertThat(infixToPostfix.getOperatorPriority(divisionSign)).isEqualTo(OperatorPriority.TOP);
61+
assertThat(infixToPostfix.getOperatorPriority(plusSign)).isEqualTo(OperatorPriority.MID);
62+
assertThat(infixToPostfix.getOperatorPriority(minusSign)).isEqualTo(OperatorPriority.MID);
63+
assertThat(infixToPostfix.getOperatorPriority(openingParenthesis))
64+
.isEqualTo(OperatorPriority.BOT);
65+
assertThat(infixToPostfix.getOperatorPriority(noSign)).isEqualTo(OperatorPriority.NONE);
66+
}
67+
68+
@Test
69+
@DisplayName("연산자의 우선순위 정보를 바탕으로 그 결과를 반환하는 함수 테스트1")
70+
void 연산자의_우선순위_정보를_바탕으로_그_결과를_반환하는_함수_테스트1() {
71+
char op1 = '*';
72+
char op2 = '+';
73+
74+
assertThat(infixToPostfix.compareOperator(op1, op2)).isEqualTo(1);
75+
}
76+
77+
@Test
78+
@DisplayName("연산자의 우선순위 정보를 바탕으로 그 결과를 반환하는 함수 테스트2")
79+
void 연산자의_우선순위_정보를_바탕으로_그_결과를_반환하는_함수_테스트2() {
80+
char op1 = '-';
81+
char op2 = '+';
82+
83+
assertThat(infixToPostfix.compareOperator(op1, op2)).isEqualTo(0);
84+
}
85+
86+
@Test
87+
@DisplayName("연산자의 우선순위 정보를 바탕으로 그 결과를 반환하는 함수 테스트3")
88+
void 연산자의_우선순위_정보를_바탕으로_그_결과를_반환하는_함수_테스트3() {
89+
char op1 = '(';
90+
char op2 = '+';
91+
92+
assertThat(infixToPostfix.compareOperator(op1, op2)).isEqualTo(-1);
93+
}
94+
}

0 commit comments

Comments
 (0)