Skip to content

Commit 1f93fa7

Browse files
committed
test: CircularLinkedList 기반 Stack 테스트 코드 작성
1 parent 3a66016 commit 1f93fa7

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

yoonexample/src/test/java/stack/StackTest.java

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class StackTest {
115115

116116
@Test
117117
@DisplayName("List Stack에 데이터 5개 넣고 뺴기")
118-
void listStack에_데이터_5개_넣고_빼기() {
118+
void ListStack에_데이터_5개_넣고_빼기() {
119119
Stack<Integer> stack = new ListStack<>();
120120

121121
stack.push(1);
@@ -140,4 +140,70 @@ class StackTest {
140140
assertThat(stack.isEmpty()).isTrue();
141141
assertThat(stack.size()).isEqualTo(0);
142142
}
143+
144+
@Test
145+
@DisplayName("CircularList Stack의 생성 및 초기화")
146+
void circularListStack의_생성_및_초기화() {
147+
Stack<Integer> stack = new CircularListStack<>();
148+
149+
assertThat(stack).isNotNull();
150+
assertThat(stack.isEmpty()).isTrue();
151+
assertThat(stack.size()).isEqualTo(0);
152+
}
153+
154+
@Test
155+
@DisplayName("CircularList Stack의 EmptyStackException 테스트")
156+
void circularListStack의_EmptyStackException_테스트() {
157+
Stack<Integer> stack = new CircularListStack<>();
158+
159+
assertThat(stack).isNotNull();
160+
assertThat(stack.isEmpty()).isTrue();
161+
assertThat(stack.size()).isEqualTo(0);
162+
assertThatThrownBy(stack::pop).isInstanceOf(EmptyStackException.class);
163+
assertThatThrownBy(stack::peek).isInstanceOf(EmptyStackException.class);
164+
}
165+
166+
@Test
167+
@DisplayName("CircularList Stack에 데이터 5개 넣기")
168+
void circularListStack에_데이터_5개_넣기() {
169+
Stack<Integer> stack = new CircularListStack<>();
170+
171+
stack.push(1);
172+
stack.push(2);
173+
stack.push(3);
174+
stack.push(4);
175+
stack.push(5);
176+
177+
assertThat(stack).isNotNull();
178+
assertThat(stack.isEmpty()).isFalse();
179+
assertThat(stack.size()).isEqualTo(5);
180+
}
181+
182+
@Test
183+
@DisplayName("CircularList Stack에 데이터 5개 넣고 뺴기")
184+
void circularListStack에_데이터_5개_넣고_빼기() {
185+
Stack<Integer> stack = new CircularListStack<>();
186+
187+
stack.push(1);
188+
stack.push(2);
189+
stack.push(3);
190+
stack.push(4);
191+
stack.push(5);
192+
193+
assertThat(stack).isNotNull();
194+
assertThat(stack.isEmpty()).isFalse();
195+
assertThat(stack.size()).isEqualTo(5);
196+
assertThat(stack.peek()).isEqualTo(5);
197+
assertThat(stack.pop()).isEqualTo(5);
198+
assertThat(stack.peek()).isEqualTo(4);
199+
assertThat(stack.pop()).isEqualTo(4);
200+
assertThat(stack.peek()).isEqualTo(3);
201+
assertThat(stack.pop()).isEqualTo(3);
202+
assertThat(stack.peek()).isEqualTo(2);
203+
assertThat(stack.pop()).isEqualTo(2);
204+
assertThat(stack.peek()).isEqualTo(1);
205+
assertThat(stack.pop()).isEqualTo(1);
206+
assertThat(stack.isEmpty()).isTrue();
207+
assertThat(stack.size()).isEqualTo(0);
208+
}
143209
}

0 commit comments

Comments
 (0)