-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayQueueTest.java
89 lines (75 loc) · 2.16 KB
/
ArrayQueueTest.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
84
85
86
87
88
89
package structure;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class ArrayQueueTest {
private ArrayQueue arrayQueue = new ArrayQueue();
@AfterEach
void afterEach() {
arrayQueue = new ArrayQueue();
}
@Test
@DisplayName("ArrayQueue: offer test")
void offer() {
// given
arrayQueue.offer(1);
arrayQueue.offer(2);
arrayQueue.offer(3);
arrayQueue.offer(4);
arrayQueue.offer(5);
arrayQueue.offer(6);
arrayQueue.offer(7);
arrayQueue.offer(8);
// when
int size = arrayQueue.size();
System.out.println(arrayQueue);
//then
assertEquals(size, 8);
}
@Test
@DisplayName("ArrayQueue: basic poll test")
void basicPoll() {
// given
arrayQueue.offer(1);
arrayQueue.offer(2);
arrayQueue.offer(3);
arrayQueue.offer(4);
arrayQueue.offer(5);
arrayQueue.offer(6);
// when
int dataA = arrayQueue.poll();
int dataB = arrayQueue.poll();
int dataC = arrayQueue.poll();
int size = arrayQueue.size();
System.out.println(arrayQueue);
// then
assertAll("basic poll",
() -> assertEquals(dataA, 1),
() -> assertEquals(dataB, 2),
() -> assertEquals(dataC, 3),
() -> assertEquals(size, 3)
);
}
@Test
@DisplayName("ArrayQueue: fail poll test")
void wrongPoll() {
// given
arrayQueue.offer(1);
arrayQueue.offer(2);
arrayQueue.offer(3);
// when
int dataA = arrayQueue.poll();
int dataB = arrayQueue.poll();
int dataC = arrayQueue.poll();
int dataD = arrayQueue.poll();
System.out.println(arrayQueue);
// then
assertAll("basic poll",
() -> assertEquals(dataA, 1),
() -> assertEquals(dataB, 2),
() -> assertEquals(dataC, 3),
() -> assertEquals(dataD, -1)
);
}
}