bool do_test(vector<int> heights, int __expected) { time_t startClock = clock(); MountainRanges *instance = new MountainRanges(); int __result = instance->countPeaks(heights); double elapsed = (double)(clock() - startClock) / CLOCKS_PER_SEC; delete instance; if (__result == __expected) { cout << "PASSED!" << " (" << elapsed << " seconds)" << endl; return true; } else { cout << "FAILED!" << " (" << elapsed << " seconds)" << endl; cout << " Expected: " << to_string(__expected) << endl; cout << " Received: " << to_string(__result) << endl; return false; } }
double test1() { int t0[] = {1, 1, 1, 1, 1, 1, 1}; vector <int> p0(t0, t0+sizeof(t0)/sizeof(int)); MountainRanges * obj = new MountainRanges(); clock_t start = clock(); int my_answer = obj->countPeaks(p0); clock_t end = clock(); delete obj; cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl; int p1 = 0; cout <<"Desired answer: " <<endl; cout <<"\t" << p1 <<endl; cout <<"Your answer: " <<endl; cout <<"\t" << my_answer <<endl; if (p1 != my_answer) { cout <<"DOESN'T MATCH!!!!" <<endl <<endl; return -1; } else { cout <<"Match :-)" <<endl <<endl; return (double)(end-start)/CLOCKS_PER_SEC; } }
int main() { { int heightsARRAY[] = {5, 6, 2, 4}; vector <int> heights( heightsARRAY, heightsARRAY+ARRSIZE(heightsARRAY) ); MountainRanges theObject; eq(0, theObject.countPeaks(heights),2); } { int heightsARRAY[] = {1, 1, 1, 1, 1, 1, 1}; vector <int> heights( heightsARRAY, heightsARRAY+ARRSIZE(heightsARRAY) ); MountainRanges theObject; eq(1, theObject.countPeaks(heights),0); } { int heightsARRAY[] = {2, 1}; vector <int> heights( heightsARRAY, heightsARRAY+ARRSIZE(heightsARRAY) ); MountainRanges theObject; eq(2, theObject.countPeaks(heights),1); } { int heightsARRAY[] = {2,5,3,7,2,8,1,3,1}; vector <int> heights( heightsARRAY, heightsARRAY+ARRSIZE(heightsARRAY) ); MountainRanges theObject; eq(3, theObject.countPeaks(heights),4); } { int heightsARRAY[] = {1}; vector <int> heights( heightsARRAY, heightsARRAY+ARRSIZE(heightsARRAY) ); MountainRanges theObject; eq(4, theObject.countPeaks(heights),1); } { int heightsARRAY[] = {1,2,3,4,4,3,2,1}; vector <int> heights( heightsARRAY, heightsARRAY+ARRSIZE(heightsARRAY) ); MountainRanges theObject; eq(5, theObject.countPeaks(heights),0); } }