double test0() { int p0 = 100; int p1 = 5; int t2[] = {6, 0, 3, 20, 22, 16}; vector <int> p2(t2, t2+sizeof(t2)/sizeof(int)); ContiguousCacheEasy * obj = new ContiguousCacheEasy(); clock_t start = clock(); int my_answer = obj->bytesRead(p0, p1, p2); clock_t end = clock(); delete obj; cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl; int p3 = 13; cout <<"Desired answer: " <<endl; cout <<"\t" << p3 <<endl; cout <<"Your answer: " <<endl; cout <<"\t" << my_answer <<endl; if (p3 != my_answer) { cout <<"DOESN'T MATCH!!!!" <<endl <<endl; return -1; } else { cout <<"Match :-)" <<endl <<endl; return (double)(end-start)/CLOCKS_PER_SEC; } }
int test3() { int n = 1; int k = 1; vector<int> addresses = {0}; ContiguousCacheEasy* pObj = new ContiguousCacheEasy(); clock_t start = clock(); int result = pObj->bytesRead(n, k, addresses); clock_t end = clock(); delete pObj; int expected = 0; if(result == expected) { cout << "Test Case 3: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 0; } else { cout << "Test Case 3: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 1; } }
int test34() { int n = 1000000; int k = 20; vector<int> addresses = {456, 54654, 5, 456, 1, 80, 999999, 999998, 876, 67}; ContiguousCacheEasy* pObj = new ContiguousCacheEasy(); clock_t start = clock(); int result = pObj->bytesRead(n, k, addresses); clock_t end = clock(); delete pObj; int expected = 180; if(result == expected) { cout << "Test Case 34: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 0; } else { cout << "Test Case 34: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 1; } }
int test26() { int n = 1000; int k = 8; vector<int> addresses = {1, 2, 10, 8, 20, 5, 26, 40, 12, 31, 9, 10, 0, 0, 0, 1, 1, 1, 24, 32, 24, 33, 25}; ContiguousCacheEasy* pObj = new ContiguousCacheEasy(); clock_t start = clock(); int result = pObj->bytesRead(n, k, addresses); clock_t end = clock(); delete pObj; int expected = 87; if(result == expected) { cout << "Test Case 26: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 0; } else { cout << "Test Case 26: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 1; } }
int test18() { int n = 500; int k = 45; vector<int> addresses = {23, 67, 98, 120, 165, 499, 0, 45, 46, 1}; ContiguousCacheEasy* pObj = new ContiguousCacheEasy(); clock_t start = clock(); int result = pObj->bytesRead(n, k, addresses); clock_t end = clock(); delete pObj; int expected = 214; if(result == expected) { cout << "Test Case 18: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 0; } else { cout << "Test Case 18: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 1; } }
int test13() { int n = 1000000; int k = 2; vector<int> addresses = {568771, 507071, 316597, 155137, 101950, 350795, 296515, 854584, 482457, 455764, 878315, 902931, 792325, 486367, 134272, 413609, 417582, 393545, 129785, 209544, 921560, 625576, 24124, 691280, 795675, 422784, 576752, 962861, 785674, 360833, 747520, 528572, 624002, 107742, 587221, 152582, 264723, 638819, 881730, 159209, 668040, 552939, 472946, 412195, 946898, 310232, 970521, 955817, 226281, 88157}; ContiguousCacheEasy* pObj = new ContiguousCacheEasy(); clock_t start = clock(); int result = pObj->bytesRead(n, k, addresses); clock_t end = clock(); delete pObj; int expected = 100; if(result == expected) { cout << "Test Case 13: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 0; } else { cout << "Test Case 13: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 1; } }
int test12() { int n = 1000000; int k = 1000000; vector<int> addresses = {383799, 925986, 163657, 28408, 791195, 29140, 447177, 314587, 411663, 103551, 292867, 377407, 377552, 283178, 859676, 739859, 65480, 994363, 138151, 168331, 553143, 17689, 68268, 653532, 914528, 375948, 961282, 578845, 426531, 87887, 288894, 264243, 892633, 627858, 411195, 352783, 555065, 210579, 81659, 192418, 17515, 419418, 27351, 326499, 365849, 873288, 693378, 950806, 212467, 504101}; ContiguousCacheEasy* pObj = new ContiguousCacheEasy(); clock_t start = clock(); int result = pObj->bytesRead(n, k, addresses); clock_t end = clock(); delete pObj; int expected = 0; if(result == expected) { cout << "Test Case 12: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 0; } else { cout << "Test Case 12: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 1; } }
int test9() { int n = 100; int k = 30; vector<int> addresses = {69, 6, 52, 66, 62, 4, 50, 85, 93, 95, 50, 6, 38, 76, 82, 40, 70, 93, 64, 46, 23, 8, 4, 33, 60, 71, 25, 82, 13, 23, 22, 33, 52, 64, 35, 34, 35, 77, 67, 16, 90, 9, 70, 70, 43, 77, 67, 62, 9, 88}; ContiguousCacheEasy* pObj = new ContiguousCacheEasy(); clock_t start = clock(); int result = pObj->bytesRead(n, k, addresses); clock_t end = clock(); delete pObj; int expected = 697; if(result == expected) { cout << "Test Case 9: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 0; } else { cout << "Test Case 9: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 1; } }
int test6() { int n = 49500; int k = 11000; vector<int> addresses = {49000, 48000, 47000, 46000, 45000, 44000, 43000, 42000, 41000, 40000, 39000, 38000, 37000, 36000, 35000, 34000, 33000, 32000, 31000, 30000, 29000, 28000, 27000, 26000, 25000, 24000, 23000, 22000, 21000, 20000, 19000, 18000, 17000, 16000, 15000, 14000, 13000, 12000, 11000, 10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 0}; ContiguousCacheEasy* pObj = new ContiguousCacheEasy(); clock_t start = clock(); int result = pObj->bytesRead(n, k, addresses); clock_t end = clock(); delete pObj; int expected = 49001; if(result == expected) { cout << "Test Case 6: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 0; } else { cout << "Test Case 6: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl; return 1; } }
// BEGIN KAWIGIEDIT TESTING // Generated by KawigiEdit 2.1.4 (beta) modified by pivanof bool KawigiEdit_RunTest(int testNum, int p0, int p1, vector <int> p2, bool hasAnswer, int p3) { cout << "Test " << testNum << ": [" << p0 << "," << p1 << "," << "{"; for (int i = 0; int(p2.size()) > i; ++i) { if (i > 0) { cout << ","; } cout << p2[i]; } cout << "}"; cout << "]" << endl; ContiguousCacheEasy *obj; int answer; obj = new ContiguousCacheEasy(); clock_t startTime = clock(); answer = obj->bytesRead(p0, p1, p2); clock_t endTime = clock(); delete obj; bool res; res = true; cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl; if (hasAnswer) { cout << "Desired answer:" << endl; cout << "\t" << p3 << endl; } cout << "Your answer:" << endl; cout << "\t" << answer << endl; if (hasAnswer) { res = answer == p3; } if (!res) { cout << "DOESN'T MATCH!!!!" << endl; } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) { cout << "FAIL the timeout" << endl; res = false; } else if (hasAnswer) { cout << "Match :-)" << endl; } else { cout << "OK, but is it right?" << endl; } cout << "" << endl; return res; }