-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyQueueTest.java
More file actions
113 lines (93 loc) · 1.65 KB
/
Copy pathMyQueueTest.java
File metadata and controls
113 lines (93 loc) · 1.65 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package queue;
import static org.junit.Assert.*;
import org.junit.Test;
public class MyQueueTest<T> {
private MyQueue<Integer> q = new MyQueue<Integer>();
@Test
public void testSize() {
q.add(2);
q.add(3);
assertEquals(2, q.size());
}
@Test
public void testSizeZero() {
assertEquals(0, q.size());
}
@Test
public void testIsEmptyYes() {
assertTrue(q.isEmpty());
}
@Test
public void testIsEmptyNo() {
q.add(5);
assertTrue(!q.isEmpty());
}
@Test
public void testAddandToString() {
q.add(5);
q.add(-17);
q.add(2);
q.add(16);
assertEquals("[5, -17, 2, 16]", q.toString());
}
@Test
public void toStringEmpty() {
assertEquals(null, q.toString());
}
@Test
public void testRemove() {
q.add(5);
q.add(7);
q.add(0);
q.add(3);
q.remove();
assertEquals("[7, 0, 3]", q.toString());
}
@Test(expected = Exception.class)
public void testRemoveNull() {
q.remove();
}
@Test
public void testPoll() {
q.add(5);
q.add(-7);
q.add(0);
q.remove();
assertEquals("[-7, 0]", q.toString());
}
@Test
public void testPollNull() {
assertEquals(null, q.poll());
}
@Test
public void testPeek() {
q.add(5);
q.add(0);
q.add(-7);
assertEquals("5", q.peek().toString());
}
@Test
public void testPeekNull() {
assertNull(q.peek());
}
@Test
public void testElement() {
q.add(2);
q.add(0);
assertEquals("2", q.element().toString());
}
@Test(expected = Exception.class)
public void testElementNull() {
q.element();
}
@Test
public void testToString() {
q.add(0);
q.add(1000);
assertEquals("[0, 1000]", q.toString());
}
@Test
public void testToStringEmpty() {
assertNull(q.toString());
}
}