// // Created by Ari Trachtenberg on 9/24. // // // #include <iostream> #include <string> #include "../problems/LabZero_ChapterTwo.h" #include "../problems/LabZero_ChapterThree.h" #include "Support/Common.h" using namespace std; bool test_labZero_pZero() { Common::redirIO("1 2 90"); // redirect input labZero_pZero(); float out = Common::getFloat(Common::restoreIO()); if (out > 2.23 && out < 2.24) { return true; } else { return false; } } bool test_labZero_pOne() { string out; // example 1 Common::redirIO("0900\n1730\n"); labZero_pOne(); out = Common::restoreIO(); if (out.find("8 hours 30 minutes")==string::npos) { return false; } // example 2 Common::redirIO("1730\n0900\n"); labZero_pOne(); out = Common::restoreIO(); if (out.find("15 hours 30 minutes")==string::npos) { return false; } // passed all tests return true; } bool test_labZero_pTwo() { Common::redirIO("123456"); labZero_pTwo(); int out = Common::getInt(Common::restoreIO()); if (out != 21) return false; return true; } bool test_labZero_pThree() { Common::redirIO("1 2 3 4"); labZero_pThree(); string out = Common::restoreIO(); if (out.find("not")!=string::npos) return false; return true; } bool test_labZero_pFour() { string out; // example 1 Common::redirIO("0 0\n0 1\n1 0\n1 1\n"); labZero_pFour(); out = Common::restoreIO(); if (out.find("square") == string::npos) return false; // example 2 Common::redirIO("0 0\n0 1\n2 0\n1 1\n"); labZero_pFour(); out = Common::restoreIO(); if (out.find("trapezoid") == string::npos) return false; return true; } bool test_labZero_pFive() { string out; // example 1 Common::redirIO("14\n"); labZero_pFive(); out = Common::restoreIO(); if (out.find("XIV")==string::npos) return false; // example 2 Common::redirIO("1978\n"); labZero_pFive(); out = Common::restoreIO(); if (out.find("MCMLXXVIII")==string::npos) return false; return true; } int main() { bool t0 = test_labZero_pZero(); bool t1 = test_labZero_pOne(); bool t2 = test_labZero_pTwo(); bool t3 = test_labZero_pThree(); bool t4 = test_labZero_pFour(); bool t5 = test_labZero_pFive(); cout << "pZero: " << (t0 ? "passed" : "failed") << endl; cout << "pOne: " << (t1 ? "passed" : "failed") << endl; cout << "pTwo: " << (t2 ? "passed" : "failed") << endl; cout << "pThree: " << (t3 ? "passed" : "failed") << endl; cout << "pFour: " << (t4 ? "passed" : "failed") << endl; cout << "pFive: " << (t5 ? "passed" : "failed") << endl; if (t0 && t1 && t2 && t3 && t4 && t5) { // all tests passed exit(0); // passed } else { exit(-1); // failed } }