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
/
LinkedListDriver.cpp
166 lines (137 loc) · 5.17 KB
/
LinkedListDriver.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Lab 10a, Write And Test The ListedList Class Template
// Programmer: Minos Park
// Editor(s) used: Sublime Text 2
// Compiler(s) used: G++
#include "LinkedList.h"
#include "LinkedList.h" // testing ifndef
#include <iostream>
#include <string>
using namespace std;
#include <cassert>
int main()
{
// print my name and this assignment's title
cout << "Lab 10a, Write And Test The ListedList Class 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;
LinkedList<int> l;
cout << "Expected isEmpty: 1 (TRUE)" << endl;
cout << "Actual isEmpty: " << l.isEmpty() << endl << endl;
assert(l.isEmpty() == 1);
cout << "Expected length: 0" << endl;
cout << "Actual length: " << l.length() << endl << endl;
assert(l.length() == 0);
cout << "insert: 111" << endl;
l.insert(111);
cout << "Expected isEmpty: 0 (FALSE)" << endl;
cout << "Actual isEmpty: " << l.isEmpty() << endl << endl;
assert(l.isEmpty() == 0);
cout << "Expected length: 1" << endl;
cout << "Actual length: " << l.length() << endl << endl;
assert(l.length() == 1);
cout << "first element test" << endl;
assert(l.first(tempInt) == 1);
cout << "Expected value: 111" << endl;
cout << "Actual value: " << tempInt << endl << endl;
assert(tempInt == 111);
cout << "insert: 222" << endl;
l.insert(222);
cout << "Expected isEmpty: 0 (FALSE)" << endl;
cout << "Actual isEmpty: " << l.isEmpty() << endl << endl;
assert(l.isEmpty() == 0);
cout << "Expected length: 2" << endl;
cout << "Actual length: " << l.length() << endl << endl;
assert(l.length() == 2);
cout << "first element test" << endl;
assert(l.first(tempInt) == 1);
cout << "Expected value: 222" << endl;
cout << "Actual value: " << tempInt << endl << endl;
assert(tempInt == 222);
l.insert(333); l.insert(444); l.insert(555);
cout << "Expected length: 5" << endl;
cout << "Actual length: " << l.length() << endl << endl;
assert(l.length() == 5);
cout << "Expected find 333: 1 (TRUE)" << endl;
cout << "Actual find 333: " << l.find(333) << endl << endl;
assert(l.find(333) == 1);
cout << "Expected find 4444: 0 (FALSE)" << endl;
cout << "Actual find 4444: " << l.find(4444) << endl << endl;
assert(l.find(4444) == 0);
cout << "get element of [2]" << endl;
tempInt = l[2];
cout << "Expected value: 333" << endl;
cout << "Actual value: " << tempInt << endl << endl;
assert(tempInt == 333);
cout << "Expected l[10]: error" << endl;
try
{
tempInt = l[10];
cout << tempInt << endl << endl;
}
catch (...)
{
cout << "Error supposed to be found. Found!" << endl << endl;
}
cout << "Remove value: 333" << endl;
tempInt = 333;
assert(l.remove(tempInt) == 1);
cout << "Expected replace(15) return: 1 (TRUE)" << endl;
cout << "Actual replace(15) return: " << l.replace(15) << endl;
assert(l.replace(15) == 1);
l.makeEmpty();
cout << "Expected length: 0" << endl;
cout << "Acutual length: " << l.length() << endl << endl;
assert(l.length() == 0);
cout << "Insert 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144" << endl << endl;
int intAry[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for(int i = 10; i != 0; i--)
l.insert(intAry[i-1]);
// object copy testing
{
LinkedList<int> listCopy = l;
cout << "Expected isEmpty: 0 (FALSE)" << endl;
cout << "Actual isEmpty: " << listCopy.isEmpty() << endl << endl;
assert(listCopy.isEmpty() == 0);
cout << "Expected length: 10" << endl;
cout << "Actual length: " << listCopy.length() << endl << endl;
assert(listCopy.length() == 10);
cout << "first element value" << endl;
cout << "Expected value: 1" << endl;
cout << "Actual value: " << listCopy.first(tempInt) << endl << endl;
assert(listCopy.first(tempInt) == 1); assert(tempInt == 1);
tempInt = 5;
assert(listCopy.find(tempInt) == 1);
assert(listCopy.getNext(tempInt) == 1); assert(tempInt == 6);
}
// object assignment testing
{
LinkedList<int> listCopy; listCopy = l;
cout << "Expected isEmpty: 0 (FALSE)" << endl;
cout << "Actual isEmpty: " << listCopy.isEmpty() << endl << endl;
assert(listCopy.isEmpty() == 0);
cout << "Expected length: 10" << endl;
cout << "Actual length: " << listCopy.length() << endl << endl;
assert(listCopy.length() == 10);
cout << "first element value" << endl;
cout << "Expected value: 1" << endl;
cout << "Actual value: " << listCopy.first(tempInt) << endl << endl;
assert(listCopy.first(tempInt) == 1); assert(tempInt == 1);
tempInt = 5;
assert(listCopy.find(tempInt) == 1);
assert(listCopy.getNext(tempInt) == 1); assert(tempInt == 6);
}
// const object assignment testing
{
const LinkedList<int> listCopy = l;
cout << "Expected isEmpty: 0 (FALSE)" << endl;
cout << "Actual isEmpty: " << listCopy.isEmpty() << endl << endl;
assert(listCopy.isEmpty() == 0);
cout << "Expected length: 10" << endl;
cout << "Actual length: " << listCopy.length() << endl << endl;
assert(listCopy.length() == 10);
}
}