/* * time_test.cpp * * Created on: Mar 29, 2019 * Author: johnsontimoj */ /////////////////////////////////////////////////////// // // Test for EE2510 (Johnson) Lab 3 // // Time Class // /////////////////////////////////////////////////////// #include "Time.h" #include "time_test.h" #include using namespace std; /////////////////////////// // // Tests for Time class // /////////////////////////// int time_test(void){ //////////////// // Variable to track overall success //////////////// int fail; fail = 0; //////////////////// // Create some objects //////////////////// Time a; Time b; Time c(11,32,45); Time d(c); ////////////////// // test setters and getters ////////////////// a.setTime(1,2,3); if(a.getHour() == 1) cout << "getHour working" << endl; else{ fail++; cout << "getHour NOT working" << endl; } if(a.getMinute() == 2) cout << "getMinute working" << endl; else{ fail++; cout << "getMinute NOT working" << endl; } if(a.getSecond() == 3) cout << "getSecond working" << endl; else{ fail++; cout << "getSecond NOT working" << endl; } if(fail == 0) cout << "///// getters working /////" << endl; else{ cout << "-----getters NOT working-----" << endl; return 1; } cout << "setTime(a,b,c) working" << endl; a.setTime(9,10); if((a.getHour() == 1) && (a.getMinute() == 9) && (a.getSecond() == 10)) cout << "setTime(a,b) working" << endl; else{ fail++; cout << "setTime(a,b) NOT working" << endl; } a.setTime(11); if((a.getHour() == 1) && (a.getMinute() == 9) && (a.getSecond() == 11)) cout << "setTime(a) working" << endl; else{ fail++; cout << "setTime(a) NOT working" << endl; } if(fail == 0) cout << "///// SetTime working /////" << endl; else{ cout << "-----setTime NOT working-----" << endl; return 2; } a.setHour(5); a.setMinute(6); a.setSecond(7); if(a.getHour() == 5) cout << "setHour working" << endl; else{ fail++; cout << "setHour NOT working" << endl; } if(a.getMinute() == 6) cout << "setMinute working" << endl; else{ fail++; cout << "setMinute NOT working" << endl; } if(a.getSecond() == 7) cout << "setSecond working" << endl; else{ fail++; cout << "setSecond NOT working" << endl; } if(fail == 0) cout << "///// setters working /////" << endl; else{ cout << "-----setters NOT working-----" << endl; return 3; } ///////////////// // Test Constructors //////////////// if(b.getHour() == 0) cout << "Default constructor setHour working" << endl; else{ fail++; cout << "Default constructor setHour NOT working" << endl; } if(b.getMinute() == 0) cout << "Default constructor setMinute working" << endl; else{ fail++; cout << "Default constructor setMinute NOT working" << endl; } if(b.getSecond() == 0) cout << "Default constructor setSecond working" << endl; else{ fail++; cout << "Default constructor setSecond NOT working" << endl; } if(c.getHour() == 11) cout << "Generalized constructor setHour working" << endl; else{ fail++; cout << "Generalized constructor setHour NOT working" << endl; } if(c.getMinute() == 32) cout << "Generalized constructor setMinute working" << endl; else{ fail++; cout << "Generalized constructor setMinute NOT working" << endl; } if(c.getSecond() == 45) cout << "Generalized constructor setSecond working" << endl; else{ fail++; cout << "Generalized constructor setSecond NOT working" << endl; } if(d.getHour() == 11) cout << "Copy constructor setHour working" << endl; else{ fail++; cout << "Copy constructor setHour NOT working" << endl; } if(d.getMinute() == 32) cout << "Copy constructor setMinute working" << endl; else{ fail++; cout << "Copy constructor setMinute NOT working" << endl; } if(d.getSecond() == 45) cout << "Copy constructor setSecond working" << endl; else{ fail++; cout << "Copy constructor setSecond NOT working" << endl; } if(fail == 0) cout << "///// Constructors working /////" << endl; else{ cout << " -----Constructors NOT working-----" << endl; return 4; } /////////////////////// // Test overflow conditions /////////////////////// a.setTime(2, 18, 124); if((a.getHour() == 2) && (a.getMinute() == 20) && (a.getSecond() == 4)) cout << "seconds overflow working" << endl; else{ fail++; cout << "seconds overflow NOT working" << endl; } a.setTime(2, 130, 33); if((a.getHour() == 4) && (a.getMinute() == 10) && (a.getSecond() == 33)) cout << "hours overflow working" << endl; else{ fail++; cout << "hours overflow NOT working" << endl; } a.setTime(2, 118, 245); if((a.getHour() == 4) && (a.getMinute() == 2) && (a.getSecond() == 5)) cout << "seconds/hours overflow working" << endl; else{ fail++; cout << "seconds/hours overflow NOT working" << endl; } if(fail == 0) cout << "///// Overflow working /////" << endl; else{ cout << " -----Overflow NOT working-----" << endl; return 5; } //////////////////// // Test operator overloading /////////////////// a.setTime(1,1,1); b.setTime(2,2,2); c = a + b; if((c.getHour() == 3) && (c.getMinute() == 3) && (c.getSecond() == 3)) cout << "+ working" << endl; else{ fail++; cout << "+ NOT working" << endl; } c = b - a; if((c.getHour() == 1) && (c.getMinute() == 1) && (c.getSecond() == 1)) cout << "- working" << endl; else{ fail++; cout << "- NOT working" << endl; } c.setTime(3,3,3); c = b = a; if((c.getHour() == 1) && (c.getMinute() == 1) && (c.getSecond() == 1)) cout << "= working" << endl; else{ fail++; cout << "= NOT working" << endl; } b.setTime(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.setTime(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.setTime(3,45,45); b = a; c = a + b; if((c.getHour() == 7) && (c.getMinute() == 31) && (c.getSecond() == 30)) 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; }