-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_LinkedListOfInts.cpp
More file actions
220 lines (216 loc) · 5.92 KB
/
Copy pathTest_LinkedListOfInts.cpp
File metadata and controls
220 lines (216 loc) · 5.92 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
/**
* @file Test_LinkedListOfInts.cpp
* @author Jason Purinton
* @Reference John Gibbons
* @date 2018.11.4
**/
#include "Test_LinkedListOfInts.h"
Test_LinkedListOfInts::Test_LinkedListOfInts(int numNodes)
{
}
void Test_LinkedListOfInts::runTests(){
//Call to tests "tx()". Prints results and returns bool true==pass
t1();//Is size zero?
t2();
t3();
t4();
t5();
t6();
t7();
t8();
t9();
}
bool Test_LinkedListOfInts::t1(){
m_testNum++;
LinkedListOfInts list;
printTestMessage(" isEmpty()= true for new list: ");
if(list.isEmpty()== true){
m_bool= true;
}
else{
m_bool= false;
}
printPassFail(m_bool);
return m_bool;
}
bool Test_LinkedListOfInts::t2(){
m_testNum++;
LinkedListOfInts list;
printTestMessage(" isEmpty()= false one addFront() and one addBack; ");
list.addFront(1);
list.addBack(4);
if(list.isEmpty()){
std::cout<<"LinkledList.size= "<<list.size()<<": ";
m_bool= false;
}
else{
std::cout<<"LinkledList.size = "<<list.size()<<": ";
m_bool= true;
}
printPassFail(m_bool);
return m_bool;
}
bool Test_LinkedListOfInts::t3(){
m_testNum++;
LinkedListOfInts list;
printTestMessage(" size()= 0 for new empty list? ");
if(list.size()== 0){
std::cout<<"LinkledList.size= "<<list.size()<<": ";
m_bool= true;
}
else{
std::cout<<"LinkledList.size= "<<list.size()<<": ";
m_bool= false;
}
printPassFail(m_bool);
return m_bool;
}
bool Test_LinkedListOfInts::t4(){
m_testNum++;
LinkedListOfInts list;
printTestMessage(" size()= 5 for three addFront() and two addBack() ");
list.addFront(1);
list.addFront(2);
list.addFront(3);
list.addBack(4);
list.addBack(5);
if(list.size()== 5){
std::cout<<"LinkledList.size= "<<list.size()<<": ";
m_bool= true;
}
else{
std::cout<<"LinkledList.size= "<<list.size()<<": ";
m_bool= false;
}
printPassFail(m_bool);
return m_bool;
}
bool Test_LinkedListOfInts::t5(){
m_testNum++;
LinkedListOfInts list;
printTestMessage(" search() is correct index with 3 addFront and 2 addBack with multiples of the same value: ");
list.addFront(-1);
list.addFront(-1);
list.addFront(0);
list.addBack(1);
list.addBack(1);
if(list.search(-1) == false){
m_bool= false;
}
else if(list.search(0) == false){
m_bool= false;
}
else if(list.search(1) == false){
m_bool= false;
}
else if(list.search(4) == false){
m_bool= false;
}
else if(list.search(5) == false){
m_bool= false;
}
else if(list.search(-2) == true){
m_bool= false;
}
else if(list.search(2) == true){
m_bool= false;
}
else{
m_bool= true;
}
printPassFail(m_bool);
return m_bool;
}
bool Test_LinkedListOfInts::t6(){
m_testNum++;
LinkedListOfInts list;
printTestMessage(" addFront(3) to the front of list? ");
list.addFront(1);
list.addFront(2);
int beforeFront= list.toVector()[0];
list.addFront(3);
int afterFront= list.toVector()[0];
if(beforeFront== afterFront){
std::cout<<"Value of front before addFront()= "<<beforeFront<<", Value of front after addFront(3)= "<<list.toVector()[0]<<": ";
m_bool= false;
}
else{
std::cout<<"Value of front before addFront()= "<<beforeFront<<", Value of front after addFront(3)= "<<list.toVector()[0]<<": ";
m_bool= true;
}
printPassFail(m_bool);
return m_bool;
}
bool Test_LinkedListOfInts::t7(){
m_testNum++;
LinkedListOfInts list;
printTestMessage(" addBack(3) add 3 to the back of list? ");
list.addBack(1);
list.addBack(2);
int beforeBack= list.toVector()[1];
list.addBack(3);
int afterBack= list.toVector()[2];
if(beforeBack== afterBack){
std::cout<<"Value of back before addback()= "<<beforeBack<<", Value of back after addback(3)= "<<afterBack<<": ";
m_bool= false;
}
else{
std::cout<<"Value of back before addback()= "<<beforeBack<<", Value of back after addback(3)= "<<afterBack<<": ";
m_bool= true;
}
printPassFail(m_bool);
return m_bool;
}
bool Test_LinkedListOfInts::t8(){
m_testNum++;
LinkedListOfInts list;
printTestMessage(" removeFront() of list? ");
list.addFront(1);
list.addFront(2);
list.addFront(3);
int beforeFront= list.toVector()[0];
list.removeFront();
int afterFront= list.toVector()[0];
if(beforeFront== afterFront){
std::cout<<"Value of front before removeFront()= "<<beforeFront<<", Value of front after removeFront()= "<<afterFront<<": ";
m_bool= false;
}
else{
std::cout<<"Value of front before removeFront()= "<<beforeFront<<", Value of front after removeFront(3)= "<<afterFront<<": ";
m_bool= true;
}
printPassFail(m_bool);
return m_bool;
}
bool Test_LinkedListOfInts::t9(){
m_testNum++;
LinkedListOfInts list;
printTestMessage(" removeBack() of list? ");
list.addBack(1);
list.addBack(2);
list.addBack(3);
int beforeBack= list.toVector()[2];
list.removeBack();
int afterBack= list.toVector()[2];
if(beforeBack== afterBack){
std::cout<<"Value of back before removeBack()= "<<beforeBack<<", Value of back after removeBack()= "<<afterBack<<": ";
m_bool= false;
}
else{
std::cout<<"Value of back before removeBack()= "<<beforeBack<<", Value of back after removeBack()= "<<afterBack<<": ";
m_bool= true;
}
printPassFail(m_bool);
return m_bool;
}
void Test_LinkedListOfInts::printPassFail(bool isPassed) const
{
if(isPassed)
std::cout<< "PASSED" << std::endl;
else
std::cout << "FAILED" << std::endl;
}
void Test_LinkedListOfInts::printTestMessage(std::string testDescription) const
{
std::cout << "Test " <<m_testNum<< testDescription;
}