-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeapPriorityQueueTest.java
63 lines (45 loc) · 1.58 KB
/
HeapPriorityQueueTest.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
package projectCode20280;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class HeapPriorityQueueTest {
@Test
void testSize() {
HeapPriorityQueue<Integer, String> pq = new HeapPriorityQueue<>();
int n = 10;
for(int i = 0; i < n; ++i) {
pq.insert(i, Integer.toString(i));
}
assertEquals(n, pq.size());
}
@Test
void testMin() {
Integer[] arr = new Integer[] {35,26,15,24,33,4,12,1,23,21,2,5};
HeapPriorityQueue<Integer, String> pq = new HeapPriorityQueue<>();
for(Integer i : arr) pq.insert(i, Integer.toString(i));
assertEquals(1, pq.min().getKey());
}
@Test
void testInsert() {
Integer[] arr = new Integer[] {35,26,15,24,33,4,12,1,23,21,2,5};
HeapPriorityQueue<Integer, String> pq = new HeapPriorityQueue<>();
for(Integer i : arr) pq.insert(i, Integer.toString(i));
assertEquals(12, pq.size());
assertEquals("[1, 2, 5, 23, 4, 12, 15, 35, 24, 33, 21, 26]", pq.toString());
}
@Test
void testRemoveMin() {
Integer[] arr = new Integer[] {35,26,15,24,33,4,12,1,23,21,2,5};
HeapPriorityQueue<Integer, String> pq = new HeapPriorityQueue<>();
for(Integer i : arr) pq.insert(i, Integer.toString(i));
assertEquals(1, pq.removeMin().getKey());
assertEquals(11, pq.size());
assertEquals(2, pq.min().getKey());
}
@Test
void testToString() {
Integer[] arr = new Integer[] {35,26,15,24,33,4,12,1,23,21,2,5};
HeapPriorityQueue<Integer, String> pq = new HeapPriorityQueue<>();
for(Integer i : arr) pq.insert(i, Integer.toString(i));
assertEquals("[1, 2, 5, 23, 4, 12, 15, 35, 24, 33, 21, 26]", pq.toString());
}
}