/* * soltime_test.cpp * * Created on: Mar 29, 2019 * Author: johnsontimoj */ /////////////////////////////////////////////////////// // // Test for EE2510 (Johnson) Lab 3 // // Sol, Time, SolTime Classes // /////////////////////////////////////////////////////// #include "SolTime.h" #include "soltime_test.h" #include using namespace std; /////////////////////////// // // Tests for SolTime class // /////////////////////////// int soltime_test(void){ //////////////// // Variable to track overall success //////////////// int fail; fail = 0; //////////////////// // Create some objects //////////////////// Time t1(5,6,7); // Time t1(2,3,4); Time t2(2,3,4); // Time t2(5,6,7); Time t3; Sol s1(9,8,7); Sol s2(3,2,1); Sol s3; SolTime a; SolTime b; SolTime c(s1,t1); SolTime d; /////////////////// // Checking == first to use throughout /////////////////// b = c; if(b==c) cout << "== working" << endl; else{ fail++; cout << "== NOT working" << endl; return 1; } ////////////////// // test setters and getters ////////////////// a.setSolTime(s2,t2); if(a.getCurSol() == s2) cout << "getCurSol working" << endl; else{ fail++; cout << "getCurSol NOT working" << endl; } if(a.getCurTime() == t2) cout << "getCurTime working" << endl; else{ fail++; cout << "getCurTime NOT working" << endl; } if(fail == 0){ cout << "///// getters working /////" << endl; cout << "setSolTime(a,b) working" << endl; }else{ cout << "-----getters NOT working-----" << endl; cout << "-----or setSolTime NOT working-----" << endl; return 2; } a.setCurSol(s1); a.setCurTime(t1); if(a.getCurSol() == s1) cout << "setCurSol working" << endl; else{ fail++; cout << "setCurSol NOT working" << endl; } if(a.getCurTime() == t1) cout << "setCurTime working" << endl; else{ fail++; cout << "setCurTime NOT working" << endl; } if(fail == 0) cout << "///// setters working /////" << endl; else{ cout << "-----setters NOT working-----" << endl; return 3; } ///////////////// // Test Constructors //////////////// if(d.getCurSol() == s3) cout << "Default constructor setCurSol working" << endl; else{ fail++; cout << "Default constructor setCurSol NOT working" << endl; } if(d.getCurTime() == t3) cout << "Default constructor setCurTime working" << endl; else{ fail++; cout << "Default constructor setCurTime NOT working" << endl; } if(c.getCurSol() == s1) cout << "Generalized constructor setCurSol working" << endl; else{ fail++; cout << "Generalized constructor setCurSol NOT working" << endl; } if(c.getCurTime() == t1) cout << "Generalized constructor setCurTime working" << endl; else{ fail++; cout << "Generalized constructor setCurTime NOT working" << endl; } if(b.getCurSol() == s1) cout << "Copy constructor setCurSol working" << endl; else{ fail++; cout << "Copy constructor setCurSol NOT working" << endl; } if(b.getCurTime() == t1) cout << "Copy constructor setCurTime working" << endl; else{ fail++; cout << "Copy constructor setCurTime NOT working" << endl; } if(fail == 0) cout << "///// Constructors working /////" << endl; else{ cout << " -----Constructors NOT working-----" << endl; return 4; } //////////////////// // Test operator overloading /////////////////// a.setSolTime(s1,t1); b.setSolTime(s2,t2); c.setSolTime(s3, t3); c = a + b; if((c.getCurSol() == (s1 + s2)) && (c.getCurTime() == (t1 + t2))) cout << "+ SolTime working" << endl; else{ fail++; cout << "+ SolTime NOT working" << endl; } c.setSolTime(s3, t3); c = a + s2; if((c.getCurSol() == (s1 + s2)) && (c.getCurTime() == (t1))) cout << "+ Sol working" << endl; else{ fail++; cout << "+ Sol NOT working" << endl; } c.setSolTime(s3, t3); c = a + t2; if((c.getCurSol() == (s1)) && (c.getCurTime() == (t1 + t2))) cout << "+ Time working" << endl; else{ fail++; cout << "+ Time NOT working" << endl; } c.setSolTime(s3, t3); c = a - b; if((c.getCurSol() == (s1 - s2)) && (c.getCurTime() == (t1 - t2))) cout << "- SolTime working" << endl; else{ fail++; cout << "- SolTime NOT working" << endl; } c.setSolTime(s3, t3); c = a - s2; if((c.getCurSol() == (s1 - s2)) && (c.getCurTime() == (t1))) cout << "- Sol working" << endl; else{ fail++; cout << "- Sol NOT working" << endl; } c.setSolTime(s3, t3); c = a - t2; if((c.getCurSol() == (s1)) && (c.getCurTime() == (t1 - t2))) cout << "- Time working" << endl; else{ fail++; cout << "- Time NOT working" << endl; } t1.setTime(2,3,4); t2.setTime(2,3,5); s1.setSol(9,8,7); s2.setSol(9,8,6); s3 = s1; a.setSolTime(s1,t1); b.setSolTime(s2,t1); c.setSolTime(s1,t2); if((a > b) && (c > a)) cout << "> working" << endl; else{ fail++; cout << "> NOT working" << endl; } if(!(b > a) || !(a > c)) cout << "> working" << endl; else{ fail++; cout << "> NOT working" << endl; } if((b < a) && (a < c)) cout << "< working" << endl; else{ fail++; cout << "< NOT working" << endl; } if(!(a < b) || !(c < a)) cout << "< working" << endl; else{ fail++; cout << "< NOT working" << endl; } c = b; if(c == b) cout << "== working" << endl; else{ fail++; cout << "== NOT working" << endl; } if(!(c == a)) cout << "== working" << endl; else{ fail++; cout << "== NOT working" << endl; } if(c != a) cout << "!= working" << endl; else{ fail++; cout << "!= NOT working" << endl; } if(!(c != b)) cout << "!= working" << endl; else{ fail++; cout << "!= NOT working" << endl; } if(fail == 0) cout << "///// operator overloading working /////" << endl; else{ cout << " -----operator overloading NOT working-----" << endl; return 6; } return 0; }