|
| 1 | +package stack; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.DisplayName; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | + |
| 8 | +class StackTest { |
| 9 | + |
| 10 | + @Test |
| 11 | + @DisplayName("Array Stack의 생성 및 초기화") |
| 12 | + void arrayStack의_생성_및_초기화() { |
| 13 | + Stack<Integer> stack = new ArrayStack<>(); |
| 14 | + |
| 15 | + assertThat(stack).isNotNull(); |
| 16 | + assertThat(stack.isEmpty()).isTrue(); |
| 17 | + assertThat(stack.size()).isEqualTo(0); |
| 18 | + } |
| 19 | + |
| 20 | + @Test |
| 21 | + @DisplayName("Array Stack에 데이터 5개 넣기") |
| 22 | + void arrayStack에_데이터_5개_넣기() { |
| 23 | + Stack<Integer> stack = new ArrayStack<>(); |
| 24 | + |
| 25 | + stack.push(1); |
| 26 | + stack.push(2); |
| 27 | + stack.push(3); |
| 28 | + stack.push(4); |
| 29 | + stack.push(5); |
| 30 | + |
| 31 | + assertThat(stack).isNotNull(); |
| 32 | + assertThat(stack.isEmpty()).isFalse(); |
| 33 | + assertThat(stack.size()).isEqualTo(5); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + @DisplayName("Array Stack에 데이터 5개 넣고 뺴기") |
| 38 | + void arrayStack에_데이터_5개_넣고_빼기() { |
| 39 | + Stack<Integer> stack = new ArrayStack<>(); |
| 40 | + |
| 41 | + stack.push(1); |
| 42 | + stack.push(2); |
| 43 | + stack.push(3); |
| 44 | + stack.push(4); |
| 45 | + stack.push(5); |
| 46 | + |
| 47 | + assertThat(stack).isNotNull(); |
| 48 | + assertThat(stack.isEmpty()).isFalse(); |
| 49 | + assertThat(stack.size()).isEqualTo(5); |
| 50 | + assertThat(stack.pop()).isEqualTo(5); |
| 51 | + assertThat(stack.pop()).isEqualTo(4); |
| 52 | + assertThat(stack.pop()).isEqualTo(3); |
| 53 | + assertThat(stack.pop()).isEqualTo(2); |
| 54 | + assertThat(stack.pop()).isEqualTo(1); |
| 55 | + assertThat(stack.isEmpty()).isTrue(); |
| 56 | + assertThat(stack.size()).isEqualTo(0); |
| 57 | + } |
| 58 | +} |
0 commit comments