-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListNodeStackTest.java
78 lines (65 loc) · 2.08 KB
/
ListNodeStackTest.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
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 ListNodeStackTest {
private ListNodeStack listNodeStack = new ListNodeStack();
@AfterEach
void afterEach() {
listNodeStack = new ListNodeStack();
}
@Test
@DisplayName("ListNodeStack: push Test")
void push() {
// given
listNodeStack.push(1);
listNodeStack.push(2);
listNodeStack.push(3);
// when
int size = listNodeStack.size();
System.out.println(listNodeStack);
// then
Assertions.assertEquals(size, 3);
}
@Test
@DisplayName("ListNodeStack: basic pop test")
void basicPop() {
// given
listNodeStack.push(1);
listNodeStack.push(2);
listNodeStack.push(3);
// when
int dataA = listNodeStack.pop();
int dataB = listNodeStack.pop();
int dataC = listNodeStack.pop();
int size = listNodeStack.size();
// then
Assertions.assertAll("basic pop",
() -> Assertions.assertEquals(dataA, 3),
() -> Assertions.assertEquals(dataB, 2),
() -> Assertions.assertEquals(dataC, 1),
() -> Assertions.assertEquals(size, 0)
);
}
@Test
@DisplayName("ListNodeStack: fail pop test")
void wrongPop() {
// given
listNodeStack.push(1);
listNodeStack.push(2);
listNodeStack.push(3);
// when: push한 데이터보다 pop한 데이터가 많다면
int dataA = listNodeStack.pop();
int dataB = listNodeStack.pop();
int dataC = listNodeStack.pop();
int dataD = listNodeStack.pop();
// then
Assertions.assertAll("wrong pop",
() -> Assertions.assertEquals(dataA, 3),
() -> Assertions.assertEquals(dataB, 2),
() -> Assertions.assertEquals(dataC, 1),
() -> Assertions.assertEquals(dataD, -1)
);
}
}