-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_priorityqueue.cpp
More file actions
206 lines (160 loc) · 3.41 KB
/
test_priorityqueue.cpp
File metadata and controls
206 lines (160 loc) · 3.41 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include "priorityqueue.h"
#include <cstdio>
#include <cassert>
#include <iostream>
void test_1() {
PriorityQueue<int> pq;
pq.push(3);
assert(pq.top() == 3);
pq.push(500);
assert(pq.top() == 500);
pq.push(100);
assert(pq.top() == 500); // 20 should remain the top
}
void test_2() {
PriorityQueue<int> pq;
pq.push(1);
pq.push(2);
pq.push(3);
pq.push(4);
assert(pq.size() == 4);
pq.pop();
assert(pq.top() == 3);
assert(pq.size() == 3);
pq.pop();
assert(pq.top() == 2);
assert(pq.size() == 2);
pq.pop();
assert(pq.size() == 1);
pq.pop();
assert(pq.size() == 0);
}
void test_3() {
PriorityQueue<int> pq;
pq.push(1);
pq.push(2);
pq.push(3);
PriorityQueue<int> copy = pq;
assert(copy.size() == pq.size());
assert(copy.top() == pq.top());
pq.pop();
assert(copy.top() == 3); // Copy should remain unchanged
assert(pq.top() == 2);
assert(copy.size() == 3);
assert(pq.size() == 2);
}
void test_4() {
PriorityQueue<int> pq;
pq.push(2);
pq.push(3);
PriorityQueue<int> assign;
assign.push(1);
assign = pq;
assert(assign.size() == pq.size());
assert(assign.top() == pq.top());
pq.pop();
assert(assign.top() == 3); // Assignment should remain unchanged
assert(assign.size() == 2);
}
void comprehensive_test() {
PriorityQueue<int> pq;
pq.push(3);
pq.push(1);
pq.push(2);
pq.push(5);
assert(pq.top() == 5);
pq.pop();
assert(pq.top() == 3);
pq.pop();
assert(pq.top() == 2);
pq.pop();
assert(pq.top() == 1);
pq.pop();
assert(pq.size() == 0);
PriorityQueue<int> pq2;
pq2.push(5);
pq2.push(15);
PriorityQueue<int> pq3 = pq2;
assert(pq3.top() == 15);
PriorityQueue<int> pq4;
pq4 = pq2;
assert(pq4.top() == 15);
}
void test_5() {
PriorityQueue<int> pq5;
assert(pq5.size() == 0);
pq5.pop();
assert(pq5.size() == 0);
}
void test_6() {
PriorityQueue<int> pq6;
pq6.push(1001);
pq6.push(1652);
pq6.push(1234);
PriorityQueue<int> copy = pq6;
pq6.push(1655);
pq6.push(2000);
assert(copy.top() == 1652);
assert(copy.size() == 3);
assert(pq6.top() == 2000);
assert(pq6.size() == 5);
}
void test_7() {
PriorityQueue<int> pq1;
PriorityQueue<int> pq2;
pq1.push(109944);
pq1.push(109945);
pq1.push(100000);
pq2 = pq1;
pq1.push(109946);
assert(pq1.top() == 109946);
pq1.pop();
assert(pq1.top() == 109945);
assert(pq2.top() == 109945);
pq2.pop();
assert(pq2.top() == 109944);
pq2.pop();
assert(pq2.top() == 100000);
pq2.pop();
assert(pq2.size() == 0);
pq1.pop();
assert(pq1.top() == 109944);
pq1.pop();
assert(pq1.size() == 1);
}
int main(int argc, char* argv[])
{
// // STEVENS TEST CODE
// // Here's some quick test code to get you started. You'll need much more
// // thorough testing, of course.
// PriorityQueue<int> q;
// // Push three elements onto the front
// q.push(1);
// q.push(2);
// q.push(3);
// // Make a copy
// PriorityQueue<int> another = q;
// // Push some more elements onto the front of the original
// q.push(4);
// q.push(5);
// while(q.size() > 0){
// printf("%d ", q.top());
// q.pop();
// }
// printf("\n");
// while(another.size() > 0){
// printf("%d ", another.top());
// another.pop();
// }
// printf("\n");
test_1();
test_2();
test_3();
test_4();
comprehensive_test();
test_5();
test_6();
test_7();
std::cout << "All test cases passed!" << std::endl;
return(0);
}