-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayStackTest.java
83 lines (70 loc) · 2.07 KB
/
ArrayStackTest.java
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package structure;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public class ArrayStackTest {
private ArrayStack arrayStack = new ArrayStack();
@AfterEach
void afterEach() {
arrayStack = new ArrayStack();
}
@Test
@DisplayName("ArrayStack: push Test")
void push() {
// given
arrayStack.push(1);
arrayStack.push(2);
arrayStack.push(3);
arrayStack.push(4);
arrayStack.push(5);
arrayStack.push(6);
// when
System.out.println(arrayStack);
int size = arrayStack.size();
// then
Assertions.assertEquals(size, 6);
}
@Test
@DisplayName("ArrayStack: basic pop test")
void basicPop() {
// given
arrayStack.push(1);
arrayStack.push(2);
arrayStack.push(3);
arrayStack.push(4);
arrayStack.push(5);
arrayStack.push(6);
// when
int dataA = arrayStack.pop();
int dataB = arrayStack.pop();
int size = arrayStack.size();
// then
Assertions.assertAll("basic pop",
() -> Assertions.assertEquals(dataA, 6),
() -> Assertions.assertEquals(dataB, 5),
() -> Assertions.assertEquals(size, 4)
);
}
@Test
@DisplayName("ArrayStack: fail pop test")
void wrongPop() {
// given
arrayStack.push(1);
arrayStack.push(2);
arrayStack.push(3);
// when
int dataA = arrayStack.pop();
int dataB = arrayStack.pop();
int dataC = arrayStack.pop();
int dataD = arrayStack.pop();
// then
Assertions.assertAll("wrong pop",
() -> Assertions.assertEquals(dataA, 3),
() -> Assertions.assertEquals(dataB, 2),
() -> Assertions.assertEquals(dataC, 1),
// 더이상 데이터가 없는데 pop
() -> Assertions.assertEquals(dataD, -1)
);
}
}