-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListNodeQueueTest.java
79 lines (64 loc) · 1.85 KB
/
ListNodeQueueTest.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
package week4.assignment5.reference;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestTemplate;
import week4.assignment4.reference.ListNodeStack;
public class ListNodeQueueTest {
@Test
void queue_init_test(){
ListNodeQueue q = new ListNodeQueue();
assertThat(q.getSize()).isEqualTo(0);
}
@Test
void queue_add_test() {
ListNodeQueue q = new ListNodeQueue();
q.add(1);
q.add(2);
assertThat(q.getSize()).isEqualTo(2);
}
@Test
void queue_poll_test() {
ListNodeQueue q = new ListNodeQueue();
q.add(1);
q.add(2);
int val = q.poll();
assertThat(val).isEqualTo(1);
assertThat(q.getSize()).isEqualTo(1);
}
@Test
void queue_peek_test() {
ListNodeQueue q = new ListNodeQueue();
q.add(1);
q.add(2);
int val = q.peek();
assertThat(val).isEqualTo(1);
assertThat(q.getSize()).isEqualTo(2);
}
@Test
void queue_pop_all_test() {
ListNodeQueue q = new ListNodeQueue();
q.add(1);
q.add(2);
q.add(3);
q.add(4);
q.add(5);
assertThat(q.getSize()).isEqualTo(5);
ArrayList<Integer> temp = new ArrayList<>();
while(!q.empty()){
temp.add(q.poll());
}
assertThat(temp.get(0)).isEqualTo(1);
assertThat(temp.get(1)).isEqualTo(2);
assertThat(temp.get(2)).isEqualTo(3);
assertThat(temp.get(3)).isEqualTo(4);
assertThat(temp.get(4)).isEqualTo(5);
assertThat(q.getSize()).isEqualTo(0);
}
@Test
void queue_pop_error() {
ListNodeQueue q = new ListNodeQueue();
assertNull(q.poll());
}
}