Example #1
0
bool KawigiEdit_RunTest(int testNum, int p0, int p1, bool hasAnswer, int p2) {
	cout << "Test " << testNum << ": [" << p0 << "," << p1;
	cout << "]" << endl;
	GuessTheNumber *obj;
	int answer;
	obj = new GuessTheNumber();
	clock_t startTime = clock();
	answer = obj->noGuesses(p0, p1);
	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" << p2 << endl;
	}
	cout << "Your answer:" << endl;
	cout << "\t" << answer << endl;
	if (hasAnswer) {
		res = answer == p2;
	}
	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;
}
Example #2
0
int main()
{
  GuessTheNumber test;
  test.run_test(-1);
  
  return 0;
}
Example #3
0
double test2() {
	int p0 = 643;
	int p1 = 327;
	GuessTheNumber * obj = new GuessTheNumber();
	clock_t start = clock();
	int my_answer = obj->noGuesses(p0, p1);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	int p2 = 7;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p2 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p2 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
Example #4
0
    void testCase4() {
		int upper = 128;
		int answer = 64;
		int expected_ = 1;
        assertEquals(4, expected_, solution.noGuesses(upper, answer));
    }
Example #5
0
    void testCase3() {
		int upper = 157;
		int answer = 157;
		int expected_ = 8;
        assertEquals(3, expected_, solution.noGuesses(upper, answer));
    }
Example #6
0
    void testCase2() {
		int upper = 643;
		int answer = 327;
		int expected_ = 7;
        assertEquals(2, expected_, solution.noGuesses(upper, answer));
    }
Example #7
0
    void testCase1() {
		int upper = 1000;
		int answer = 750;
		int expected_ = 2;
        assertEquals(1, expected_, solution.noGuesses(upper, answer));
    }
Example #8
0
    void testCase0() {
		int upper = 9;
		int answer = 6;
		int expected_ = 3;
        assertEquals(0, expected_, solution.noGuesses(upper, answer));
    }