-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtPodDriver.cpp
More file actions
327 lines (236 loc) · 7.72 KB
/
UtPodDriver.cpp
File metadata and controls
327 lines (236 loc) · 7.72 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/*#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}*/
/* utPod_driver.cpp
Demo Driver for the UtPod.
Roger Priebe
EE 312 10/16/18
This is a basic driver for the UtPod.
You will want to do more complete testing.
*/
#include <cstdlib>
#include <iostream>
#include <string>
#include "Song.h"
#include "UtPod.h"
using namespace std;
void testGetTotalMemory();
void testGetRemainingMemory();
void testSwap();
void testSongBoolOps();
void testGetNumSongs();
void testClearMemory();
void testSortSongList();
void testShuffle();
void recommendedTestDriver();
int main(int argc, char *argv[])
{
testGetTotalMemory();
testGetRemainingMemory();
testSwap();
testSongBoolOps();
testGetNumSongs();
testClearMemory();
testSortSongList();
testShuffle();
recommendedTestDriver();
/*
*/
}
void testGetTotalMemory(){
cout << "**Testing getTotalMemory() function**" << endl;
UtPod t1;
cout << "UtPod t1 total memory = " << t1.getTotalMemory() << endl;
UtPod t2(5);
cout << "UtPod t2 total memory = " << t2.getTotalMemory() << endl;
UtPod t3(0);
cout << "UtPod t3 total memory = " << t3.getTotalMemory() << endl;
UtPod t4(-10);
cout << "UtPod t4 total memory = " << t4.getTotalMemory() << endl;
UtPod t5(600);
cout << "UtPod t5 total memory = " << t5.getTotalMemory() << endl;
cout << endl << endl;
}
void testGetRemainingMemory(){
cout << "**Testing getRemainingMemory() function**" << endl;
UtPod t;
Song s1("Abcd", "John", 6);
t.addSong(s1);
cout << "Result 1 = " << t.getRemainingMemory() << endl;
Song s2("qwerty", "Ben", 200);
t.addSong(s2);
cout << "Result 2 = " << t.getRemainingMemory() << endl;
Song s3("Too big", "Jerk", 307);
cout << "Should return NO_MEMORY (-1): " << t.addSong(s3) << endl;
cout << "Result 3 = " << t.getRemainingMemory() << " (should be same as Result 2)" << endl;
cout << endl << endl;}
void testSwap(){
cout << "**Testing swap() function**" << endl;
Song s1("Hey Jude1", "Beatles", 4);
Song s2("Hey Jude2", "Beatles", 5);
cout << "Before swap:" << endl << "s1 = " << s1.getTitle()
<< ", s2 = " << s2.getTitle() << endl;
s1.swap(s2);
cout << "After swap:" << endl << "s1 = " << s1.getTitle()
<< ", s2 = " << s2.getTitle() << endl;
cout << endl << endl;
}
void testGetNumSongs(){
cout << "**Testing getNumSongs() function**" << endl;
UtPod t;
cout << "Number of songs before adding any: " << t.getNumSongs() << endl;
Song s1("Hey Jude1", "Beatles", 4);
t.addSong(s1);
Song s2("Hey Jude2", "Beatles", 5);
t.addSong(s2);
cout << "Number of songs after adding 2: " << t.getNumSongs() << endl;
t.removeSong(s1);
t.removeSong(s2);
cout << "Number of songs after removing those 2: " <<t.getNumSongs() << endl;
cout << endl << endl;
}
void testSongBoolOps(){
cout << "**Testing overridden boolean operations for Song class**" << endl;
//Test by varying the titles, artists, and sizes
//Make sure s1 is greater than s2 in any of your test cases
Song s1("abcd", "Beatles", 4);
Song s2("abcd", "Beatles", 5);
cout << "Testing '<':" << endl
<< "Should return true: " << (s1<s2) << endl << endl;
cout << "Testing '>':" << endl
<< "Should return false (testing '>'): " << (s1>s2) << endl << endl;
cout << "Testing '==':" << endl
<< "Should return false (testing '=='): " << (s1==s2) << endl << endl;
cout << endl << endl;
}
void testClearMemory(){
cout << "**Testing clearMemory() function**" << endl;
UtPod t;
t.clearMemory();
cout << "Number of songs after clearing memory of already empty UtPod: " << t.getNumSongs() << endl;
Song s1("Hey Jude1", "Beatles", 4);
t.addSong(s1);
Song s2("Hey Jude2", "Beatles", 5);
t.addSong(s2);
cout << "Just added 2 songs to UtPod: " << t.getNumSongs() << endl;
t.clearMemory();
cout << "Number of songs after calling clearMemory(): " << t.getNumSongs() << endl;
cout << endl << endl;
}
void testSortSongList(){
cout << "**Testing sortSongList() function**" << endl;
UtPod t;
t.sortSongList();
cout << endl << "Result of sorting empty list: " << endl;
t.showSongList();
Song s1("Hey Jude1", "Beatles", 4);
t.addSong(s1);
cout << endl << "List of length 1 song: " << endl;
cout << "---Before sort: " << endl;
t.showSongList();
cout << "--After sort: " << endl;
t.sortSongList();
t.showSongList();
Song s2("Hey Jude2", "Beatles", 5);
t.addSong(s2);
cout << endl << "List of length 2 songs: " << endl;
cout << "---Before sort:" << endl;
t.showSongList();
cout << "---After sort:" << endl;
t.sortSongList();
t.showSongList();
Song s3("Hey John", "Beatles", 5);
t.addSong(s3);
Song s4("Hey John", "Beatles", 2);
t.addSong(s4);
Song s5("Hey John", "Apple", 5);
t.addSong(s5);
Song s6("abcd", "Alpha", 3);
t.addSong(s6);
Song s7("aBcd", "Alpha", 5);
t.addSong(s7);
Song s8("Hey Jude3", "Beatles", 5);
t.addSong(s8);
cout << endl << "List of length " << t.getNumSongs() << " songs: " << endl;
cout << "---Before sort:" << endl;
t.showSongList();
cout << "---After sort:" << endl;
t.sortSongList();
t.showSongList();
cout << endl << endl;
}
void testShuffle(){
cout << "**Testing shuffle() function**" << endl;
UtPod t;
cout << "***********************" << endl << "Empty list:" << endl;
t.showSongList();
cout << "Shuffling empty list:" << endl;
t.shuffle();
t.showSongList();
cout << endl << "***********************" << endl << "List of one:" << endl;
Song s3("a", "albert", 5);
t.addSong(s3);
t.showSongList();
cout << "After shuffle:" << endl;
t.shuffle();
t.showSongList();
Song s4("b", "bob", 2);
t.addSong(s4);
Song s5("c", "carl", 5);
t.addSong(s5);
Song s6("d", "daniel", 3);
t.addSong(s6);
Song s7("e", "evan", 5);
t.addSong(s7);
Song s8("f", "frank", 5);
t.addSong(s8);
cout << endl << "***********************" << endl << "Long List:" << endl;
t.showSongList();
t.shuffle();
cout << endl << "After Shuffle:" << endl;
t.showSongList();
t.shuffle();
cout << endl << "Shuffled Again:" << endl;
t.showSongList();
cout << endl << endl;
}
void recommendedTestDriver(){
cout << "**This is the general driver created to help us get started with the code**" << endl;
UtPod t;
Song s1("Beatles", "Hey Jude1", 4);
int result = t.addSong(s1);
cout << "result = " << result << endl;
t.showSongList();
Song s2("Beatles", "Hey Jude2", 5);
result = t.addSong(s2);
cout << "result = " << result << endl;
t.showSongList();
Song s3("Beatles", "Hey Jude3", 6);
result = t.addSong(s3);
cout << "result = " << result << endl;
Song s4("Beatles", "Hey Jude4", 7);
result = t.addSong(s4);
cout << "result = " << result << endl;
Song s5("Beatles", "Hey Jude5", 241);
result = t.addSong(s5);
cout << "add result = " << result << endl;
t.showSongList();
result = t.removeSong(s2);
cout << "delete result = " << result << endl;
result = t.removeSong(s3);
cout << "delete result = " << result << endl;
t.showSongList();
result = t.removeSong(s1);
cout << "delete result = " << result << endl;
result = t.removeSong(s5);
cout << "delete result = " << result << endl;
result = t.removeSong(s4);
cout << "delete result = " << result << endl;
t.showSongList();
result = t.addSong(s5);
cout << "add result = " << result << endl;
t.showSongList();
cout << "memory = " << t.getRemainingMemory() << endl;
}