/************************************* * test code for assignment # 5 * Engr. 4892 Term 4 * Clinton Munden ************************************/ #include #include "assign5.h" #include "assign5_impl.h" using namespace std; int main() { cout << "Some simple test code for assignment #5\n"; cout << "This will test your functions to see if they are correct.\n"; cout << "\n.........................................\n"; cout << " Testing rSize function"; cout << "\n.........................................\n\n"; A5Tree mine; for(int x = 1; x < 10; x++){ mine.insert(x); } vector v = mine.inorderList(); int vsiz = v.size(); cout << "The number of nodes is 9. You said " << vsiz << ". --- "; if(vsiz == 9){ cout << "<-PASS->\n\n";} else{cout << "<-FAIL->\n\n";} A5Tree miner; vector r = miner.inorderList(); int rsiz = r.size(); cout << "The number of nodes is 0. You said " << rsiz << ". --- "; if(rsiz == 0){ cout << "<-PASS->\n\n";} else{cout << "<-FAIL->\n\n";} char pause; cout << "Press Enter to Continue...\n"; cin.get(pause); cout << "\n.........................................\n"; cout << " Testing rRemove function"; cout << "\n.........................................\n\n"; cout << "This is the original inorder traversal: "; for (int i = 0; i < vsiz; i++){ cout << v[i] << " "; } cout << "\n\n"; cout << "Removing the Root Node (1): "; int bad = 0; Path myPath; mine.remove(myPath); vector a = mine.inorderList(); int asiz = a.size(); for(i = 0; i < asiz; i++){ cout << a[i] << " "; if(a[i] == 1){bad = 1;} } if(bad == 1){cout << "<-FAIL->\n";} else{cout << " <-PASS->\n";} A5Tree mineb; for(x = 1; x < 10; x++){ mineb.insert(x); } cout << "Removing another Node (2): "; myPath.push_back(Left); mineb.remove(myPath); vector b = mineb.inorderList(); int bsiz = b.size(); for(i = 0; i < bsiz; i++){ cout << b[i] << " "; if(b[i] == 2){bad = 1;} } if(bad == 1){cout << "<-FAIL->\n";} else{cout << " <-PASS->\n";} A5Tree minec; myPath.clear(); for(x = 1; x < 10; x++){ minec.insert(x); } cout << "Removing another Node (3): "; myPath.push_back(Right); minec.remove(myPath); vector c = minec.inorderList(); int csiz = c.size(); for(i = 0; i < csiz; i++){ cout << c[i] << " "; if(c[i] == 3){bad = 1;} } if(bad == 1){cout << "<-FAIL->\n";} else{cout << " <-PASS->\n";} A5Tree mined; myPath.clear(); for(x = 1; x < 10; x++){ mined.insert(x); } cout << "Removing another Node (4): "; myPath.push_back(Left); myPath.push_back(Left); mined.remove(myPath); vector d = mined.inorderList(); int dsiz = d.size(); for(i = 0; i < dsiz; i++){ cout << d[i] << " "; if(d[i] == 4){bad = 1;} } if(bad == 1){cout << "<-FAIL->\n";} else{cout << " <-PASS->\n";} A5Tree minee; myPath.clear(); for(x = 1; x < 10; x++){ minee.insert(x); } cout << "Removing another Node (5): "; myPath.push_back(Right); myPath.push_back(Left); minee.remove(myPath); vector e = minee.inorderList(); int esiz = e.size(); for(i = 0; i < esiz; i++){ cout << e[i] << " "; if(e[i] == 5){bad = 1;} } if(bad == 1){cout << "<-FAIL->\n";} else{cout << " <-PASS->\n";} A5Tree minef; myPath.clear(); for(x = 1; x < 10; x++){ minef.insert(x); } cout << "Removing another Node (6): "; myPath.push_back(Left); myPath.push_back(Right); minef.remove(myPath); vector f = minef.inorderList(); int fsiz = f.size(); for(i = 0; i < fsiz; i++){ cout << f[i] << " "; if(f[i] == 6){bad = 1;} } if(bad == 1){cout << "<-FAIL->\n";} else{cout << " <-PASS->\n";} A5Tree mineg; myPath.clear(); for(x = 1; x < 10; x++){ mineg.insert(x); } cout << "Removing another Node (7): "; myPath.push_back(Left); myPath.push_back(Left); myPath.push_back(Left); mineg.remove(myPath); vector g = mineg.inorderList(); int gsiz = g.size(); for(i = 0; i < gsiz; i++){ cout << g[i] << " "; if(g[i] == 7){bad = 1;} } if(bad == 1){cout << "<-FAIL->\n";} else{cout << " <-PASS->\n";} A5Tree mineh; myPath.clear(); for(x = 1; x < 10; x++){ mineh.insert(x); } cout << "Removing another Node (8): "; myPath.push_back(Right); myPath.push_back(Right); mineh.remove(myPath); vector h = mineh.inorderList(); int hsiz = h.size(); for(i = 0; i < hsiz; i++){ cout << h[i] << " "; if(h[i] == 8){bad = 1;} } if(bad == 1){cout << "<-FAIL->\n";} else{cout << " <-PASS->\n";} A5Tree minej; myPath.clear(); for(x = 1; x < 10; x++){ minej.insert(x); } cout << "Removing another Node (9): "; myPath.push_back(Right); myPath.push_back(Left); myPath.push_back(Left); minej.remove(myPath); vector j = minej.inorderList(); int jsiz = j.size(); for(i = 0; i < jsiz; i++){ cout << j[i] << " "; if(j[i] == 9){bad = 1;} } if(bad == 1){cout << "<-FAIL->\n";} else{cout << " <-PASS->\n";} A5Tree minek; myPath.clear(); cout << "Passing in an Empty Tree: "; myPath.push_back(Right); myPath.push_back(Left); myPath.push_back(Left); minek.remove(myPath); if(minek.getStatus() == 2){cout << "<-PASS->\n";} else{cout << " <-FAIL->\n";} int n = mine.getStatus(); if(n == 0){cout << "err = Ok\n";} else if(n == 1){cout << "err = NewFail\n";} else if(n == 2){cout << "err = NoSuchElement\n";} else if(n == 3){cout << "err = DuplicateElement\n";} else{cout << "You're having trouble with your err returns!\n";} return 0; }