-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPriorityQueueTest.java
More file actions
executable file
·101 lines (83 loc) · 2.24 KB
/
Copy pathPriorityQueueTest.java
File metadata and controls
executable file
·101 lines (83 loc) · 2.24 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
import static org.junit.Assert.*;
import org.junit.Test;
import java.io.*;
import java.util.*;
public class PriorityQueueTest {
@Test
public void testPriorityQueue() throws IOException {
PriorityQueue<String> h = new PriorityQueue<String>();
h.push("apple"); h.push("bear"); h.push("duck"); h.push("yarn");
h.push("horse"); h.push("pear");
assertTrue(h.pop().equals("apple"));
assertTrue(h.contains("pear"));
System.out.println(h);
assertTrue(h.pop().equals("bear"));
assertTrue(h.pop().equals("duck"));
assertTrue(h.pop().equals("horse"));
assertTrue(h.pop().equals("pear"));
assertTrue(h.pop().equals("yarn"));
assertTrue(h.size() == 0);
PriorityQueue<Integer> ints = new PriorityQueue<Integer>();
for(int i = 0; i < 10; i++) {
ints.push(i);
assertTrue(ints.contains(i));
}
ints.clear();
assertTrue(ints.size() == 0);
}
@Test
public void test() throws IOException {
BufferedReader f = new BufferedReader(new FileReader("PriorityQueueTest"));
PriorityQueue<Integer> test = new PriorityQueue<Integer>();
List<Integer> ints = new java.util.ArrayList<Integer>();
for(int i = 0; i <= 10000; i++) {
test.push(Integer.parseInt(f.readLine()));
}
for(int i = 0; i <= 10000; i++) {
assertTrue(test.peek() == i);
assertTrue(test.pop() == i);
}
assertTrue(test.size() == 0);
for(int i = 0; i < 1000000; i++) {
ints.add((int)(Math.random() * 10000 + 1));
}
for(int i = 0; i < ints.size(); i++) {
test.push(ints.get(i));
}
Collections.sort(ints);
for(int i = 0; i < 1000000; i++) {
assertTrue(test.pop().equals(ints.get(i)));
}
f.close();
}
/*
@Test
public void testPush() {
fail("Not yet implemented");
}
@Test
public void testClear() {
fail("Not yet implemented");
}
@Test
public void testComparator() {
fail("Not yet implemented");
}
@Test
public void testContains() {
fail("Not yet implemented");
}
@Test
public void testPeek() {
fail("Not yet implemented");
}
@Test
public void testPop() {
fail("Not yet implemented");
}
@Test
public void testSize() {
fail("Not yet implemented");
}
*/
}