This repository has been archived by the owner on Oct 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PriorityQueueDriver.cpp
149 lines (122 loc) · 4.46 KB
/
PriorityQueueDriver.cpp
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
// Lab 12a, Write And Test A Priority Queue Template
// Programmer: Minos Park
// Editor(s) used: Sublime Text 2
// Compiler(s) used: G++
#include "PriorityQueue.h"
#include "PriorityQueue.h" // testing ifndef
#include <iostream>
#include <string>
using namespace std;
#include <cassert>
int main()
{
// print my name and this assignment's title
cout << "Lab 12a, Write And Test A Priority Queue Template\n";
cout << "Programmer: Minos Park\n";
cout << "Editor(s) used: Sublime Text 2\n";
cout << "Compiler(s) used: G++\n";
cout << "File: " << __FILE__ << endl;
cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
int tempInt;
PriorityQueue<int> l;
cout << "Expected empty: 1 (TRUE)" << endl;
cout << "Actual empty: " << l.empty() << endl << endl;
assert(l.empty() == 1);
cout << "Expected size: 0" << endl;
cout << "Actual size: " << l.size() << endl << endl;
assert(l.size() == 0);
cout << "Enqueue: 111" << endl;
l.enqueue(111);
cout << "Expected empty: 0 (FALSE)" << endl;
cout << "Actual empty: " << l.empty() << endl << endl;
assert(l.empty() == 0);
cout << "Expected size: 1" << endl;
cout << "Actual size: " << l.size() << endl << endl;
assert(l.size() == 1);
cout << "Expected top value: 111" << endl;
cout << "Actual top value: " << l.top() << endl << endl;
assert(l.top() == 111);
cout << "Enqueue: 222" << endl;
l.enqueue(222);
cout << "Expected empty: 0 (FALSE)" << endl;
cout << "Actual empty: " << l.empty() << endl << endl;
assert(l.empty() == 0);
cout << "Expected size: 2" << endl;
cout << "Actual size: " << l.size() << endl << endl;
assert(l.size() == 2);
cout << "Expected top value: 222" << endl;
cout << "Actual top value: " << l.top() << endl << endl;
assert(l.top() == 222);
l.enqueue(333); l.enqueue(444); l.enqueue(555);
cout << "Expected size: 5" << endl;
cout << "Actual size: " << l.size() << endl << endl;
assert(l.size() == 5);
cout << "Dequeue" << endl;
tempInt = l.dequeue();
cout << "Expected value: 555" << endl;
cout << "Actual value: " << tempInt << endl << endl;
assert(tempInt == 555);
cout << "Dequeue" << endl;
tempInt = l.dequeue();
cout << "Expected value: 444" << endl;
cout << "Actual value: " << tempInt << endl << endl;
assert(tempInt == 444);
l.clear();
cout << "Expected size: 0" << endl;
cout << "Acutual size: " << l.size() << endl << endl;
assert(l.size() == 0);
cout << "Insert 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144" << endl << endl;
int intAry[10] = {1, 2, 3, 5, 4, 6, 10, 8, 9, 7};
for(int i = 10; i != 0; i--)
l.enqueue(intAry[i-1]);
for (int i = 10; i != 0; i--)
assert(l.dequeue() == i);
for(int i = 10; i != 0; i--)
l.enqueue(intAry[i-1]);
// object copy testing
{
PriorityQueue<int> listCopy = l;
cout << "Expected empty: 0 (FALSE)" << endl;
cout << "Actual empty: " << listCopy.empty() << endl << endl;
assert(listCopy.empty() == 0);
cout << "Expected size: 10" << endl;
cout << "Actual size: " << listCopy.size() << endl << endl;
assert(listCopy.size() == 10);
cout << "top element value" << endl;
cout << "Expected top value: 10" << endl;
cout << "Actual top value: " << listCopy.top() << endl << endl;
assert(listCopy.top() == 10);
listCopy.dequeue();
assert(listCopy.top() == 9);
for (int i = 9; i != 0; i--)
assert(listCopy.dequeue() == i);
}
// object assignment testing
{
PriorityQueue<int> listCopy; listCopy = l;
cout << "Expected empty: 0 (FALSE)" << endl;
cout << "Actual empty: " << listCopy.empty() << endl << endl;
assert(listCopy.empty() == 0);
cout << "Expected size: 10" << endl;
cout << "Actual size: " << listCopy.size() << endl << endl;
assert(listCopy.size() == 10);
cout << "top element value" << endl;
cout << "Expected top value: 10" << endl;
cout << "Actual top value: " << listCopy.top() << endl << endl;
assert(listCopy.top() == 10);
listCopy.dequeue();
assert(listCopy.top() == 9);
for (int i = 9; i != 0; i--)
assert(listCopy.dequeue() == i);
}
// const object assignment testing
{
const PriorityQueue<int> listCopy = l;
cout << "Expected empty: 0 (FALSE)" << endl;
cout << "Actual empty: " << listCopy.empty() << endl << endl;
assert(listCopy.empty() == 0);
cout << "Expected size: 10" << endl;
cout << "Actual size: " << listCopy.size() << endl << endl;
assert(listCopy.size() == 10);
}
}