-
Notifications
You must be signed in to change notification settings - Fork 7
/
Test_ariel.cpp
227 lines (203 loc) · 8.48 KB
/
Test_ariel.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
#include "doctest.h"
#include "FamilyTree.hpp"
#include <string>
using namespace std;
TEST_CASE("Reference add Tree case") {
family::Tree T ("Yosef");
T.addFather("Yosef", "Yaakov")
.addMother("Yosef", "Rachel")
.addFather("Yaakov", "Isaac")
.addMother("Yaakov", "Rivka")
.addFather("Isaac", "Avraham")
.addFather("Avraham", "Terah");
}
TEST_CASE("Yosef Tree case") {
// Add test case
family::Tree T ("Yosef");
T.addFather("Yosef", "Yaakov");
T.addMother("Yosef", "Rachel");
CHECK_THROWS(T.addFather("Yosef", "Yaakov")); // duplicate father
CHECK_THROWS(T.addMother("Yosef", "Rivka")); // duplicate mother
T.addFather("Yaakov", "Isaac");
T.addMother("Yaakov", "Rivka");
T.addFather("Rachel", "Avi");
T.addMother("Rachel", "Ruti");
T.addFather("Isaac", "Avraham");
T.addMother("Isaac", "Ruti");
CHECK_THROWS(T.addFather("Isaac", "Israel")); // duplicate father
CHECK_THROWS(T.addMother("Isaac", "Ruti")); // duplicate mother
T.addFather("Avraham", "Yosi");
T.addMother("Avraham", "Shelly");
T.addFather("Avi", "Israel");
T.addMother("Avi", "Sara");
CHECK_THROWS(T.addFather("Avraham", "Avraham")); // duplicate father
CHECK_THROWS(T.addMother("Avraham", "Sara")); // duplicate mother
// Relation test case
CHECK(T.relation("Yaakov") == string("father"));
CHECK(T.relation("Rachel") == string("mother"));
CHECK(T.relation("Isaac") == string("grandfather"));
CHECK(T.relation("Rivka") == string("grandmother"));
CHECK(T.relation("Avi") == string("grandfather"));
CHECK((T.relation("Ruti") == string("grandmother") || T.relation("Ruti") == string("great-grandmother")));
CHECK(T.relation("Avraham") == string("great-grandfather"));
CHECK((T.relation("Ruti") == string("grandmother") || T.relation("Ruti") == string("great-grandmother")));
CHECK(T.relation("Israel") == string("great-grandfather"));
CHECK(T.relation("Sara") == string("great-grandmother"));
CHECK(T.relation("Yosi") == string("great-great-grandfather"));
CHECK(T.relation("Shelly") == string("great-great-grandmother"));
CHECK(T.relation("xyz") == string("unrelated"));
CHECK(T.relation("Omer") == string("unrelated"));
CHECK(T.relation("Ariel") == string("unrelated"));
CHECK(T.relation(" ") == string("unrelated"));
CHECK(T.relation(" Ariel") == string("unrelated"));
// Find test case
CHECK(T.find("father") == string("Yaakov"));
CHECK(T.find("mother") == string("Rachel"));
CHECK((T.find("grandfather") == string("Isaac") || T.find("grandfather") == string("Avi")));
CHECK((T.find("grandmother") == string("Rivka") || T.find("grandmother") == string("Ruti")));
CHECK((T.find("great-grandmother") == string("Sara") || T.find("great-grandmother") == string("Ruti")));
CHECK((T.find("great-grandfather") == string("Avraham") || T.find("great-grandfather") == string("Israel")));
CHECK(T.find("great-great-grandfather") == string("Yosi"));
CHECK(T.find("great-great-grandmother") == string("Shelly"));
CHECK_THROWS(T.find("grandfatrher"));
CHECK_THROWS(T.find("great"));
CHECK_THROWS(T.find(" "));
CHECK_THROWS(T.find(" great"));
CHECK_THROWS(T.find("grandfatrher "));
CHECK_THROWS(T.find("great,great,grandmother"));
CHECK_THROWS(T.find("great?grandmother"));
CHECK_THROWS(T.find("great grandmother"));
// Remove test case
//CHECK_THROWS(T.remove("Yosef")); // removing the root is an error
CHECK_THROWS(T.remove(" ")); // removing a non-existent person
CHECK_THROWS(T.remove("xyz"));
CHECK_THROWS(T.remove("Ariel"));
CHECK_THROWS(T.remove(" Rivka"));
T.remove("Yosi"); // remove the great-great-grandfather
CHECK_THROWS(T.find("great-great-grandfather")); // A removed relation does not exist
T.addFather("Avraham", "Ido"); // Add a new father after removal
T.remove("Avi");
CHECK_THROWS(T.addFather("Avi", "Israel")); // add to a removed person
T.addFather("Rachel", "Shmual");
T.remove("Isaac");
T.remove("Rivka");
T.remove("Ruti");
CHECK_THROWS(T.find("grandmother"));
CHECK_THROWS(T.addFather("Isaac", "Avraham"));
CHECK_THROWS(T.addMother("Isaac", "Ruti"));
CHECK_THROWS(T.addFather("Rivka", "Israel"));
CHECK_THROWS(T.addMother("Rivka", "Sara"));
T.remove("Yaakov"); // remove father
T.remove("Rachel"); // remove mother
CHECK_THROWS(T.find("father"));
CHECK_THROWS(T.find("mother"));
CHECK_THROWS(T.addFather("Yaakov", "Avraham")); // add to non-existent person
CHECK_THROWS(T.addMother("Yaakov", "Ruti")); // add to non-existent person
CHECK_THROWS(T.addFather("Rachel", "Avraham")); // add to non-existent person
CHECK_THROWS(T.addMother("Rachel", "Ruti")); // add to non-existent person
}
/*
TEST_CASE("Strange string Tree case") {
// Add test case
family::Tree T ("OliVeR$");
T.addFather("OliVeR$", "fEliXX");
T.addMother("OliVeR$", "#miA");
CHECK_THROWS(T.addFather("OliVeR$", "Yaa kov"));
CHECK_THROWS(T.addMother("OliVeR$", "Rivka"));
T.addFather("fEliXX", "eLi9");
T.addMother("fEliXX", "IRis-");
T.addFather("#miA", "osC7ar");
T.addMother("#miA", "AvA");
T.addFather("IRis-", "le0");
T.addMother("IRis-", "aB3igaIl");
CHECK_THROWS(T.addFather("IRis-", "Israel"));
CHECK_THROWS(T.addMother("IRis-", "Ruti"));
// Relation test case
CHECK(T.relation("fEliXX") == string("father"));
CHECK(T.relation("#miA") == string("mother"));
CHECK(T.relation("eLi9") == string("grandfather"));
CHECK(T.relation("IRis-") == string("grandmother"));
CHECK(T.relation("osC7ar") == string("grandfather"));
CHECK(T.relation("AvA") == string("grandmother"));
CHECK(T.relation("le0") == string("great-grandfather"));
CHECK(T.relation("aB3igaIl") == string("great-grandmother"));
CHECK(T.relation("fEli XX") == string("unrelated"));
CHECK(T.relation("&miA") == string("unrelated"));
CHECK(T.relation("leo") == string("unrelated"));
CHECK(T.relation(" ") == string("unrelated"));
CHECK(T.relation(" osC7ar") == string("unrelated"));
// Find test case
CHECK(T.find("father") == string("fEliXX"));
CHECK(T.find("mother") == string("#miA"));
CHECK((T.find("grandfather") == string("eLi9") || T.find("grandfather") == string("osC7ar")));
CHECK((T.find("grandmother") == string("IRis-") || T.find("grandmother") == string("AvA")));
CHECK(T.find("great-grandfather") == string("le0"));
CHECK(T.find("great-grandmother") == string("aB3igaIl"));
CHECK_THROWS(T.find("grandfatrher"));
CHECK_THROWS(T.find("great"));
CHECK_THROWS(T.find(" "));
CHECK_THROWS(T.find(" great"));
CHECK_THROWS(T.find("grandfatrher "));
CHECK_THROWS(T.find("great,great,grandmother"));
CHECK_THROWS(T.find("great?grandmother"));
CHECK_THROWS(T.find("great grandmother"));
// Remove test case
CHECK_THROWS(T.remove("OliVeR$"));
T.remove("aB3igaIl");
CHECK_THROWS(T.find("great-grandmother"));
T.addMother("IRis-", "aB3igaIl");
T.remove("fEliXX");
CHECK_THROWS(T.addFather("eLi9", "Israel"));
CHECK_THROWS(T.addMother("eLi9", "Ruti"));
CHECK_THROWS(T.find("great-grandfather"));
T.addFather("OliVeR$", "fEliXX");
T.remove("osC7ar");
CHECK_THROWS(T.find("grandfather"));
T.remove("#miA");
CHECK_THROWS(T.addFather("#miA", "Avraham"));
CHECK_THROWS(T.addMother("#miA", "Ruti"));
T.remove("fEliXX");
CHECK_THROWS(T.find("father"));
CHECK_THROWS(T.find("mother"));
}
TEST_CASE("Empty string Tree case") {
// Add test case
family::Tree T (" ");
T.addFather(" ", " ");
T.addMother(" ", " ");
CHECK_THROWS(T.addFather(" ", "Yakov"));
CHECK_THROWS(T.addMother(" ", " "));
T.addFather(" ", " ");
T.addMother(" ", " ");
CHECK_THROWS(T.addFather(" ", " "));
CHECK_THROWS(T.addMother(" ", "Rut i"));
// Relation test case
CHECK(T.relation(" ") == string("father"));
CHECK(T.relation(" ") == string("mother"));
CHECK(T.relation(" ") == string("grandfather"));
CHECK(T.relation(" ") == string("grandmother"));
CHECK(T.relation("fli XX") == string("unrelated"));
CHECK(T.relation("leo") == string("unrelated"));
CHECK(T.relation(" osC7ar") == string("unrelated"));
// Find test case
CHECK(T.find("father") == string(" "));
CHECK(T.find("mother") == string(" "));
CHECK(T.find("grandfather") == string(" "));
CHECK(T.find("grandmother") == string(" "));
CHECK_THROWS(T.find(" "));
CHECK_THROWS(T.find("great"));
CHECK_THROWS(T.find(" great"));
// Remove test case
CHECK_THROWS(T.remove(" "));
T.remove(" ");
CHECK_THROWS(T.find("grandmother"));
T.remove(" ");
CHECK_THROWS(T.addFather(" ", " "););
CHECK_THROWS(T.addMother(" ", " Ru ti"););
CHECK_THROWS(T.find("father"));
T.remove(" ");
CHECK_THROWS(T.find("mother"));
CHECK_THROWS(T.addFather(" ", " "););
CHECK_THROWS(T.addMother(" ", "Rut i "););
}
*/