-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
317 lines (289 loc) · 6.58 KB
/
test.cpp
File metadata and controls
317 lines (289 loc) · 6.58 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
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include "proj6.h"
using namespace std;
void printMyLL(lnode* head) {
lnode* cur = head;
while (cur != nullptr) {
printf("%s \n", cur->value);
cur = cur->next;
}
}
void printMyList(myNode* head) {
myNode* cur = head;
while (cur != nullptr) {
printf("%d ", cur->getValue());
cur = cur->getNext();
}
printf("\n");
}
MyList copyTest(MyList x) {
// printMyList(x.getHead());
MyList newx;
newx = x;
// printMyList(newx.getHead());
return newx;
}
int main() {
// Testing for MyList class
MyList ml;
MyList ml2;
// Testing isEmpty & default constructor
if (!ml.isEmpty()) {
printf("wrong!");
return 1;
} // CHECKED :D
// Testing push_back without duplicates
ml.push_back(0);
ml.push_back(1);
ml.push_back(2);
ml.push_back(3);
ml.push_back(4);
ml.push_back(5);
ml.push_back(6);
ml.push_back(7);
ml.push_back(8);
ml.push_back(9);
// testing copy constructor
ml2 = copyTest(ml);
// printMyList(ml2.getHead());
// printMyList(ml.getHead()); // CHECKED :D
// Testing getSize
// printf("size: %d\n", ml.getSize()); // CHECKED :D
// Testing getNthVal
for (int i = 0; i < 10; i++) {
// printf("%d ", ml.getNthVal(i));
}
printf("\n"); // CHECKED :D
// testing =copyconstructor
ml2 = ml;
// printf("this is ml:\n");
// printMyList(ml.getHead());
// printf("this is ml2:\n");
// printMyList(ml2.getHead()); // CHECKED :D
// Testing remove without duplicates
ml.remove(9);
// printMyList(ml.getHead());
// expect 012345678
ml.remove(8);
// printMyList(ml.getHead());
// expect 01234567
ml.remove(0);
// printMyList(ml.getHead());
// expect 1234567
ml.remove(1);
// printMyList(ml.getHead());
// expect 234567
ml.remove(5);
// printMyList(ml.getHead());
// expect 23467
ml.remove(4);
// printMyList(ml.getHead());
// expect 2367
ml.remove(2);
// printMyList(ml.getHead());
// expect 367
ml.remove(7);
// printMyList(ml.getHead());
// expect 36
ml.remove(6);
// printMyList(ml.getHead());
// expect 3
ml.remove(3);
if (!ml.isEmpty()) {
printf("wrong!");
return 1;
} // CHECKED :D
// Testing push_back with duplicates
ml.push_back(0);
ml.push_back(0);
ml.push_back(0);
ml.push_back(3);
ml.push_back(4);
ml.push_back(6);
ml.push_back(6);
ml.push_back(9);
ml.push_back(8);
ml.push_back(0);
// printMyList(ml.getHead()); // CHECKED :D
// Testing remove with duplicates
ml.remove(0);
// printMyList(ml.getHead());
// expect 003466980
ml.remove(8);
// printMyList(ml.getHead());
// expect 00346690
ml.remove(0);
// printMyList(ml.getHead());
// expect 0346690
ml.remove(6);
// printMyList(ml.getHead());
// expect 034690
ml.remove(6);
// printMyList(ml.getHead());
// expect 03490
ml.remove(4);
// printMyList(ml.getHead());
// expect 0390
ml.remove(0);
// printMyList(ml.getHead());
// expect 390
ml.remove(0);
// printMyList(ml.getHead());
// expect 39
ml.remove(9);
// printMyList(ml.getHead());
// expect 3
ml.remove(3);
if (!ml.isEmpty()) {
printf("wrong!");
return 1;
} // CHECKED :d
// ULT TEST: CHECKING VALGRIND
ml.push_back(0);
ml.push_back(0);
ml.push_back(0);
ml.push_back(3);
ml.push_back(4);
ml.push_back(6);
ml.push_back(6);
ml.push_back(9);
ml.push_back(8);
ml.push_back(0);
// printMyList(ml.getHead()); // CHECKED :D
// PROOF:
// ==2015==
// ==2015== HEAP SUMMARY:
// ==2015== in use at exit: 0 bytes in 0 blocks
// ==2015== total heap usage: 32 allocs, 32 frees, 74,208 bytes allocated
// ==2015==
// ==2015== All heap blocks were freed -- no leaks are possible
// ==2015==
// ==2015== For counts of detected and suppressed errors, rerun with: -v
// ==2015== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
/* ************************************************************************ */
// Testing for Island class
Island is;
// Island is:
// nList = nullptr
// visit = false
// prev = -1
if (is.getnList() != nullptr) {
printf("wrong!");
return 1;
} // CHECKED :D
is.setnList(&ml); // list: 0003466980
is.visited();
is.setPrev(20);
// Island is:
// nList = m1 : 0003466980
// visit = true
// prev = 20
if (!is.isVisited()) {
printf("wrong!");
return 1;
} // CHECKED :D
// testing =operator
Island is2;
is2 = is;
// printMyList(is2.getnList()->getHead()); // list: 0003466980
if (!is2.isVisited()) {
printf("wrong!");
return 1;
}
if (is2.getPrev() != 20) {
printf("wrong!");
return 1;
} // CHECKED :D
// printMyList(is.getnList()->getHead()); // CHECKED :D
// printf("prev: %d\n", is.getPrev()); // CHECKED :D
// & still passes valgrind XD
/* ************************************************************************ */
// Testing for myLL class
// Kinda upset I have to do this
myLL l;
// testing default constructor && isEmpty
if (!l.isEmpty()) {
printf("wrong!");
return 1;
}
// testing push_back
l.push_back("I'm");
l.push_back("so");
l.push_back("frikin");
l.push_back("pissed!");
// printMyLL(l.getHead());
// testing getSize
if (l.getSize() != 4) {
printf("wrong");
return 1;
}
// testing exist pt 1
if (!l.exist("so")) {
printf("wrong");
return 1;
}
// testing exist pt 2
if (!l.exist("pissed!")) {
printf("wrong");
return 1;
}
// testing exist pt 3
if (!l.exist("I'm")) {
printf("wrong");
return 1;
}
// testing exist pt 4
if (l.exist("wrong")) {
printf("wrong");
return 1;
}
// testing pop_front
l.pop_front();
l.pop_front();
l.pop_front();
l.pop_front();
if (!l.isEmpty()) {
printf("wrong!");
return 1;
}
// testing exist pt 5
if (l.exist("so")) {
printf("wrong");
return 1;
}
// printMyLL(l.getHead());
l.push_back("I'm");
l.push_back("so");
l.push_back("frikin");
l.push_back("pissed!");
// printMyLL(l.getHead());
// testing pop_back
// printf("%s\n", l.peek_back());
l.pop_back();
// printf("%s\n", l.peek_back());
l.pop_back();
// printf("%s\n", l.peek_back());
l.pop_back();
// printf("%s\n", l.peek_back());
l.pop_back();
// printMyLL(l.getHead());
if (!l.isEmpty()) {
printf("wrong!");
return 1;
}
// Testing destructor
l.push_back("I'm");
l.push_back("so");
// printMyLL(l.getHead());
l.clear();
// printMyLL(l.getHead());
l.push_back("I'm");
l.push_back("so");
l.push_back("frikin");
l.push_back("pissed!");
// printMyLL(l.getHead());
// Passed all tests + valgrind :)
return 0;
}