// BEGIN KAWIGIEDIT TESTING // Generated by KawigiEdit 2.1.4 (beta) modified by pivanof bool KawigiEdit_RunTest(int testNum, vector <string> p0, vector <int> p1, vector <int> p2, int p3, bool hasAnswer, double p4) { cout << "Test " << testNum << ": [" << "{"; for (int i = 0; int(p0.size()) > i; ++i) { if (i > 0) { cout << ","; } cout << "\"" << p0[i] << "\""; } cout << "}" << "," << "{"; for (int i = 0; int(p1.size()) > i; ++i) { if (i > 0) { cout << ","; } cout << p1[i]; } cout << "}" << "," << "{"; for (int i = 0; int(p2.size()) > i; ++i) { if (i > 0) { cout << ","; } cout << p2[i]; } cout << "}" << "," << p3; cout << "]" << endl; GraphWalkWithProbabilities *obj; double answer; obj = new GraphWalkWithProbabilities(); clock_t startTime = clock(); answer = obj->findprob(p0, p1, p2, p3); 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" << p4 << endl; } cout << "Your answer:" << endl; cout << "\t" << answer << endl; if (hasAnswer) { res = fabs(p4 - answer) <= 1e-9 * max(1.0, fabs(p4)); } 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; }
// BEGIN CUT HERE void main( int argc, char* argv[] ) { { string graphARRAY[] = {"1"}; vector <string> graph( graphARRAY, graphARRAY+ARRSIZE(graphARRAY) ); int winprobARRAY[] = {1}; vector <int> winprob( winprobARRAY, winprobARRAY+ARRSIZE(winprobARRAY) ); int looseprobARRAY[] = {1}; vector <int> looseprob( looseprobARRAY, looseprobARRAY+ARRSIZE(looseprobARRAY) ); GraphWalkWithProbabilities theObject; eq(0, theObject.findprob(graph, winprob, looseprob, 0),0.5); } { string graphARRAY[] = {"11","11"}; vector <string> graph( graphARRAY, graphARRAY+ARRSIZE(graphARRAY) ); int winprobARRAY[] = {60,40}; vector <int> winprob( winprobARRAY, winprobARRAY+ARRSIZE(winprobARRAY) ); int looseprobARRAY[] = {40,60}; vector <int> looseprob( looseprobARRAY, looseprobARRAY+ARRSIZE(looseprobARRAY) ); GraphWalkWithProbabilities theObject; eq(1, theObject.findprob(graph, winprob, looseprob, 0),0.6); } { string graphARRAY[] = {"11","11"}; vector <string> graph( graphARRAY, graphARRAY+ARRSIZE(graphARRAY) ); int winprobARRAY[] = {2,3}; vector <int> winprob( winprobARRAY, winprobARRAY+ARRSIZE(winprobARRAY) ); int looseprobARRAY[] = {3,4}; vector <int> looseprob( looseprobARRAY, looseprobARRAY+ARRSIZE(looseprobARRAY) ); GraphWalkWithProbabilities theObject; eq(2, theObject.findprob(graph, winprob, looseprob, 0),0.4285714285714286); } { string graphARRAY[] = {"110","011","001"}; vector <string> graph( graphARRAY, graphARRAY+ARRSIZE(graphARRAY) ); int winprobARRAY[] = {2,1,10}; vector <int> winprob( winprobARRAY, winprobARRAY+ARRSIZE(winprobARRAY) ); int looseprobARRAY[] = {20,20,10}; vector <int> looseprob( looseprobARRAY, looseprobARRAY+ARRSIZE(looseprobARRAY) ); GraphWalkWithProbabilities theObject; eq(3, theObject.findprob(graph, winprob, looseprob, 0),0.405); } { string graphARRAY[] = {"111","111","011"}; vector <string> graph( graphARRAY, graphARRAY+ARRSIZE(graphARRAY) ); int winprobARRAY[] = {100,1,1}; vector <int> winprob( winprobARRAY, winprobARRAY+ARRSIZE(winprobARRAY) ); int looseprobARRAY[] = {0,50,50}; vector <int> looseprob( looseprobARRAY, looseprobARRAY+ARRSIZE(looseprobARRAY) ); GraphWalkWithProbabilities theObject; eq(4, theObject.findprob(graph, winprob, looseprob, 2),0.5); } }