Newer
Older
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
/*
* Compile this test against your .h files to make sure they compile. Note how
* the eecs281 priority queues can be constructed with the different types. We
* suggest adding to this file or creating your own test cases to test your
* priority queue implementations.
*
* These tests are /not/ a complete test of your priority queues!
*/
#include "BinaryPQ.h"
#include "Eecs281PQ.h"
#include "JarJarPQ.h"
#include "PairingPQ.h"
#include "SortedPQ.h"
#include <cassert>
#include <iostream>
using std::cout;
using std::endl;
#include <string>
using std::string;
#include <vector>
using std::vector;
void testPriorityQueue(Eecs281PQ<int>& pq, const string& pqType);
void testPairing(vector<int>&);
int main()
{
JarJarPQ<int> jarJarPq;
SortedPQ<int> sortedPq;
BinaryPQ<int> binaryPq;
// Jar-Jar should pass already.
testPriorityQueue(jarJarPq, "Jar-Jar");
testPriorityQueue(sortedPq, "Sorted");
testPriorityQueue(binaryPq, "Binary");
vector<int> vec;
vec.push_back(0);
vec.push_back(1);
testPairing(vec);
}
void testPriorityQueue(Eecs281PQ<int>& pq, const string& pqType)
{
cout << "Testing priority queue: " << pqType << endl;
pq.push(3);
pq.push(4);
assert(pq.size() == 2);
assert(pq.top() == 4);
pq.pop();
assert(pq.size() == 1);
assert(pq.top() == 3);
assert(!pq.empty());
pq.pop();
assert(pq.size() == 0);
assert(pq.empty());
}
void testPairing(vector<int> & vec)
{
Eecs281PQ<int> * pq1 = new PairingPQ<int>(vec.begin(), vec.end());
Eecs281PQ<int> * pq2 = new PairingPQ<int>(*((PairingPQ<int> *)pq1));
// This line is different just to show two different ways to declare a
// pairing heap: as an Eecs281PQ and as a PairingPQ. Yay for inheritance!
PairingPQ<int> * pq3 = new PairingPQ<int>();
*pq3 = *((PairingPQ<int> *)pq2);
pq1->push(3);
pq2->pop();
pq1->size();
pq1->empty();
assert(pq1->top() == 3);
delete pq1;
delete pq2;
delete pq3;
}