/* * sol_test.cpp * * Created on: Mar 29, 2019 * Author: johnsontimoj */ /////////////////////////////////////////////////////// // // Test for EE2510 (Johnson) Lab 3 // // Sol Class // /////////////////////////////////////////////////////// #include "Sol.h" #include "sol_test.h" #include using namespace std; /////////////////////////// // // Tests for Sol class // /////////////////////////// int sol_test(void){ //////////////// // Variable to track overall success //////////////// int fail; fail = 0; //////////////////// // Create some objects //////////////////// Sol a; Sol b; Sol c(11,4,15); Sol d(c); ////////////////// // test setters and getters ////////////////// a.setSol(1,2,3); if(a.getYears() == 1) cout << "getYears working" << endl; else{ fail++; cout << "getYears NOT working" << endl; } if(a.getMonths() == 2) cout << "getMonths working" << endl; else{ fail++; cout << "getMonths NOT working" << endl; } if(a.getDays() == 3) cout << "getDays working" << endl; else{ fail++; cout << "getDays NOT working" << endl; } if(fail == 0) cout << "///// getters working /////" << endl; else{ cout << "-----getters NOT working-----" << endl; return 1; } cout << "setSol(a,b,c) working" << endl; a.setSol(9,10); if((a.getYears() == 1) && (a.getMonths() == 9) && (a.getDays() == 10)) cout << "setSol(a,b) working" << endl; else{ fail++; cout << "setSol(a,b) NOT working" << endl; } a.setSol(11); if((a.getYears() == 1) && (a.getMonths() == 9) && (a.getDays() == 11)) cout << "setSol(a) working" << endl; else{ fail++; cout << "setSol(a) NOT working" << endl; } if(fail == 0) cout << "///// SetSol working /////" << endl; else{ cout << "-----setSol NOT working-----" << endl; return 2; } a.setYears(5); a.setMonths(6); a.setDays(7); if(a.getYears() == 5) cout << "setYears working" << endl; else{ fail++; cout << "setYears NOT working" << endl; } if(a.getMonths() == 6) cout << "setMonths working" << endl; else{ fail++; cout << "setMonths NOT working" << endl; } if(a.getDays() == 7) cout << "setDays working" << endl; else{ fail++; cout << "setDays NOT working" << endl; } if(fail == 0) cout << "///// setters working /////" << endl; else{ cout << "-----setters NOT working-----" << endl; return 3; } ///////////////// // Test Constructors //////////////// if(b.getYears() == 0) cout << "Default constructor setYears working" << endl; else{ fail++; cout << "Default constructor setYears NOT working" << endl; } if(b.getMonths() == 0) cout << "Default constructor setMonths working" << endl; else{ fail++; cout << "Default constructor setMonths NOT working" << endl; } if(b.getDays() == 0) cout << "Default constructor setDays working" << endl; else{ fail++; cout << "Default constructor setDays NOT working" << endl; } if(c.getYears() == 11) cout << "Generalized constructor setYears working" << endl; else{ fail++; cout << "Generalized constructor setYears NOT working" << endl; } if(c.getMonths() == 4) cout << "Generalized constructor setMonths working" << endl; else{ fail++; cout << "Generalized constructor setMonths NOT working" << endl; } if(c.getDays() == 15) cout << "Generalized constructor setDays working" << endl; else{ fail++; cout << "Generalized constructor setDays NOT working" << endl; } if(d.getYears() == 11) cout << "Copy constructor setYears working" << endl; else{ fail++; cout << "Copy constructor setYears NOT working" << endl; } if(d.getMonths() == 4) cout << "Copy constructor setMonths working" << endl; else{ fail++; cout << "Copy constructor setMonths NOT working" << endl; } if(d.getDays() == 15) cout << "Copy constructor setDays working" << endl; else{ fail++; cout << "Copy constructor setDays NOT working" << endl; } if(fail == 0) cout << "///// Constructors working /////" << endl; else{ cout << " -----Constructors NOT working-----" << endl; return 4; } /////////////////////// // Test overflow conditions /////////////////////// a.setSol(2, 3, 66); if((a.getYears() == 2) && (a.getMonths() == 5) && (a.getDays() == 5)) cout << "days overflow working" << endl; else{ fail++; cout << "days overflow NOT working" << endl; } a.setSol(3, 14, 15); if((a.getYears() == 4) && (a.getMonths() == 2) && (a.getDays() == 15)) cout << "months overflow working" << endl; else{ fail++; cout << "months overflow NOT working" << endl; } a.setSol(2, 118, 245); if((a.getYears() == 12) && (a.getMonths() == 6) && (a.getDays() == 3)) cout << "days/months overflow working" << endl; else{ fail++; cout << "days/months overflow NOT working" << endl; } if(fail == 0) cout << "///// Overflow working /////" << endl; else{ cout << " -----Overflow NOT working-----" << endl; return 5; } //////////////////// // Test operator overloading /////////////////// a.setSol(1,1,1); b.setSol(2,2,2); c = a + b; if((c.getYears() == 3) && (c.getMonths() == 3) && (c.getDays() == 3)) cout << "+ working" << endl; else{ fail++; cout << "+ NOT working" << endl; } c = b - a; if((c.getYears() == 1) && (c.getMonths() == 1) && (c.getDays() == 1)) cout << "- working" << endl; else{ fail++; cout << "- NOT working" << endl; } c.setSol(3,3,3); c = b = a; if((c.getYears() == 1) && (c.getMonths() == 1) && (c.getDays() == 1)) cout << "= working" << endl; else{ fail++; cout << "= NOT working" << endl; } b.setSol(2,2,2); if(b > a) cout << "> working" << endl; else{ fail++; cout << "> NOT working" << endl; } if(!(a > b)) cout << "> working" << endl; else{ fail++; cout << "> NOT working" << endl; } if(a < b) cout << "< working" << endl; else{ fail++; cout << "< NOT working" << endl; } if(!(b < a)) cout << "< working" << endl; else{ fail++; cout << "< NOT working" << endl; } c.setSol(2,2,2); 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; } //////////////////// // a few additional tests ////////////////// a.setSol(3,45,45); b = a; c = a + b; if((c.getYears() == 13) && (c.getMonths() == 8) && (c.getDays() == 28)) cout << "additional test 1 working" << endl; else{ fail++; cout << "additional test 1 NOT working" << endl; } if(fail == 0) cout << "///// additional tests working /////" << endl; else{ cout << " ----- additional tests NOT working -----" << endl; return 7; } return 0; }