-
Notifications
You must be signed in to change notification settings - Fork 1
/
unit_test.cpp
235 lines (190 loc) · 9.11 KB
/
unit_test.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
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
#include "bst.h"
#include <assert.h>
#include <sstream>
//testing member class
int test_mem_verify_ID(int ID)
{
member myMember;
myMember.set_ID(ID);
assert((myMember.verify_ID(ID) == 1));
return 1;
}
int test_mem_input(int ID, bool status, float fee)
{
service_list * list = new service_list();
member myMember("Layla", "Smith", "1234 WhereamI", "Portland", "OR", 97016, "[email protected]", status, ID, fee, list);
assert(myMember.get_member_ID() == ID);
assert(myMember.get_status_mem() == status);
assert(myMember.get_fee_mem() == fee);
return 1;
}
int test_mem_update_status(bool status)
{
member myMember;
myMember.set_status(status);
assert(myMember.get_status_mem() == status);
return 1;
}
int test_member_display(BST_member * memberTree)
{
std::stringstream ss;
service_list * list = new service_list();
member myMember("Layla", "Smith", "1234 WhereamI", "Portland", "OR", 97016, "[email protected]", true, 123456789, 10, list);
member * myMember1 = &myMember;
memberTree->add_new_member_(myMember1);
myMember1->display(ss);
assert(ss.str() == "\n\tMember Information:\n\tThe ID of the membership : 123456789\n\tThe status of the membership : VALID!\n\tThe fee of the membership : 10");
return 1;
}
//testing provider class
int test_provider_verify_ID(int ID)
{
provider myProvider;
myProvider.set_ID(ID);
assert(myProvider.verify_provider_ID(ID) == 1);
return 1;
}
int test_provider_display(BST_provider * providerTree)
{
std::stringstream ss;
service_list * list = new service_list();
provider myProvider("Layla", "Smith", "1234 WhereamI", "Portland", "OR", 97016, "[email protected]", 10, 123456789, 100, list);
provider * myProvider1 = &myProvider;
providerTree->add_new_provider_(myProvider1);
myProvider.display(ss);
assert(ss.str() == "\n\tThe ID of the provider: 123456789\n\tThe number of consultations: 10\n\tThe fee of the membership: 100\n\tThe services list: \n\n");
return 1;
}
//("Layla", "Smith", "1234 WhereamI", "Portland", "OR", 97016, "[email protected]", 100, 123456789, 10000)
int test_provider_input(const string& first, const string& last, const string& address, const string& city, const string& state, int zipcode, const string& email, int num, int ID, float fee)
{
service_list * list = new service_list();
provider myProvider(first, last, address, city, state, zipcode, email, num, ID, fee, list);
assert(myProvider.get_provider_ID() == ID);
assert(myProvider.get_num_consul() == num);
assert(myProvider.get_total_fee() == fee);
return 1;
}
//testing BST
int test_provider_BST_add(const string& first, const string& last, const string& address, const string& city, const string& state, int zipcode, const string& email, int num, int ID, float fee, BST_provider * providerTree)
{
service_list * list = new service_list();
provider myProvider(first, last, address, city, state, zipcode, email, num, ID, fee, list);
provider * myProvider1 = &myProvider;
providerTree->add_new_provider_(myProvider1);
assert(providerTree->display_by_ID(ID) == true);
return 1;
}
//Unit test 4
int test_member_BST_add(const string& first, const string& last, const string& address, const string& city, const string& state, int zipcode, const string& email, int ID, bool status, float fee, BST_member * memberTree)
{
service_list * list = new service_list();
member myMember(first, last, address, city, state, zipcode, email, status, ID, fee, list);
member * myMember1 = &myMember;
memberTree->add_new_member_(myMember1);
assert(memberTree->display_by_ID(ID) == 1);
return 1;
}
int test_provider_BST_remove(const string& first, const string& last, const string& address, const string& city, const string& state, int zipcode, const string& email, int num, int ID, float fee, BST_provider * providerTree)
{
service_list * list = new service_list();
provider myProvider(first, last, address, city, state, zipcode, email, num, ID, fee, list);
provider * myProvider1 = &myProvider;
providerTree->add_new_provider_(myProvider1);
assert(providerTree->display_by_ID(ID) == 1);
assert(providerTree->remove_provider_(ID) == 1);
assert(providerTree->display_by_ID(ID) == 0);
return 1;
}
int test_member_BST_remove(const string& first, const string& last, const string& address, const string& city, const string& state, int zipcode, const string& email, int ID, bool status, float fee, BST_member * memberTree)
{
service_list * list = new service_list();
member myMember(first, last, address, city, state, zipcode, email, status, ID, fee, list);
member * myMember1 = &myMember;
memberTree->add_new_member_(myMember1);
assert(memberTree->display_by_ID(ID) == 1);
assert(memberTree->remove_member_(ID) == 1);
assert(memberTree->display_by_ID(ID) == 0);
return 1;
}
int test_member_greater()
{
member * smallerMem = new member;
member * largerMem = new member;
smallerMem->set_ID(111111111);
largerMem->set_ID(222222222);
assert(largerMem>smallerMem == 1);
assert(smallerMem>largerMem == 0);
return 1;
}
int test_member_lesser()
{
member * smallerMem = new member;
member * largerMem = new member;
smallerMem->set_ID(111111111);
largerMem->set_ID(222222222);
assert(largerMem<smallerMem == 0);
assert(smallerMem<largerMem == 1);
return 1;
}
int test_provider_greater()
{
provider * smallerProv = new provider;
provider * largerProv = new provider;
smallerProv->set_ID(111111111);
largerProv->set_ID(222222222);
assert(largerProv>smallerProv == 1);
assert(smallerProv>largerProv == 0);
return 1;
}
int test_provider_lesser()
{
provider * smallerProv = new provider;
provider * largerProv = new provider;
smallerProv->set_ID(111111111);
largerProv->set_ID(222222222);
assert(largerProv<smallerProv == 0);
assert(smallerProv<largerProv == 1);
return 1;
}
int main()
{
BST_member * memberTree = new BST_member;
BST_member * memberTree1 = new BST_member;
BST_member * memberTree2 = new BST_member;
BST_provider * providerTree = new BST_provider;
BST_provider * providerTree1 = new BST_provider;
BST_provider * providerTree2 = new BST_provider;
manager myManager;
if(test_mem_verify_ID(123456789) && test_mem_verify_ID(234567891) && test_mem_verify_ID(456789123))
cout << "Unit test 1: Completed successfully. Member function verify_ID() runs without errors." << endl;
if(test_mem_input(123456789, true, 23.5) && test_mem_input(987654321, true, 1))
cout << "Unit test 2: Completed successfully. Member function setInput() runs without errors." << endl;
if(test_mem_update_status(true) && test_mem_update_status(false))
cout << "\nUnit test 3: Completed successfully. Member function set_status() runs without errors." << endl;
if(test_member_BST_add("Layla", "Smith", "1234 WhereamI", "Portland", "OR", 97016, "[email protected]", 123456789, true, 10, memberTree))
cout << "\nUnit test 4: Completed successfully. BST function add_new_member() runs without errors." << endl;
if(test_provider_BST_add("Layla", "Smith", "1234 WhereamI", "Portland", "OR", 97016, "[email protected]", 100, 123456789, 10, providerTree))
cout << "\nUnit test 5: Completed successfully. BST function add_new_provider() runs without errors." << endl;
if(test_provider_BST_remove("Layla", "Smith", "1234 WhereamI", "Portland", "OR", 97016, "[email protected]", 100, 123456789, 10, providerTree1))
cout << "\nUnit test 6: Completed successfully. BST function remove_provider_() runs without errors." << endl;
if(test_member_BST_remove("Layla", "Smith", "1234 WhereamI", "Portland", "OR", 97016, "[email protected]", 123456789, true, 10, memberTree1))
cout << "\nUnit test 7: Completed successfully. BST function remove_member_() runs without errors." << endl;
if(test_provider_input("Layla", "Smith", "1234 WhereamI", "Portland", "OR", 97016, "[email protected]", 100, 123456789, 10000))
cout << "\nUnit test 8: Completed successfully. Provider function setInput() runs without errors." << endl;
// if(test_provider_display(providerTree2))
// cout << "\nUnit test 9: Completed successfully. Provider function display() runs without errors." << endl;
if(test_member_display(memberTree2))
cout << "\nUnit test 10: Completed successfully. Member function display() runs without errors." << endl;
if(test_provider_verify_ID(123456789) && test_provider_verify_ID(987654321))
cout << "\nUnit test 11: Completed successfully. Provider function setInput() runs without errors." << endl;
if(test_member_greater())
cout << "\nUnit test 12: Completed successfully. Member overloaded operator > runs without errors." << endl;
if(test_member_lesser())
cout << "\nUnit test 13: Completed successfully. Member overloaded operator < runs without errors." << endl;
if(test_provider_greater())
cout << "\nUnit test 14: Completed successfully. Provider overloaded operator > runs without errors." << endl;
if(test_provider_lesser())
cout << "\nUnit test 15: Completed successfully. Provider overloaded operator < runs without errors." << endl;
return 0;
}