Ejemplo n.º 1
0
int test3() {
    vector<int> eatenCandies = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1000};
    AverageCandyLifetime* pObj = new AverageCandyLifetime();
    clock_t start = clock();
    double result = pObj->getAverage(eatenCandies);
    clock_t end = clock();
    delete pObj;
    double expected = 365.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;
    }
}
Ejemplo n.º 2
0
int test37() {
    vector<int> eatenCandies = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
    AverageCandyLifetime* pObj = new AverageCandyLifetime();
    clock_t start = clock();
    double result = pObj->getAverage(eatenCandies);
    clock_t end = clock();
    delete pObj;
    double expected = 252.80769230769232;
    if(result == expected) {
        cout << "Test Case 37: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 0;
    } else {
        cout << "Test Case 37: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 1;
    }
}
Ejemplo n.º 3
0
int test38() {
    vector<int> eatenCandies = {555, 354, 485, 669, 118, 211, 669, 336, 999, 1000, 561, 972};
    AverageCandyLifetime* pObj = new AverageCandyLifetime();
    clock_t start = clock();
    double result = pObj->getAverage(eatenCandies);
    clock_t end = clock();
    delete pObj;
    double expected = 225.19656516091788;
    if(result == expected) {
        cout << "Test Case 38: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 0;
    } else {
        cout << "Test Case 38: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 1;
    }
}
Ejemplo n.º 4
0
int test24() {
    vector<int> eatenCandies = {928, 967, 920, 937, 966, 938, 957, 999, 937, 951, 942, 924};
    AverageCandyLifetime* pObj = new AverageCandyLifetime();
    clock_t start = clock();
    double result = pObj->getAverage(eatenCandies);
    clock_t end = clock();
    delete pObj;
    double expected = 197.00325532289284;
    if(result == expected) {
        cout << "Test Case 24: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 0;
    } else {
        cout << "Test Case 24: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 1;
    }
}
Ejemplo n.º 5
0
int test23() {
    vector<int> eatenCandies = {492, 547, 598, 647, 693, 0, 87, 167, 241, 310, 375, 435};
    AverageCandyLifetime* pObj = new AverageCandyLifetime();
    clock_t start = clock();
    double result = pObj->getAverage(eatenCandies);
    clock_t end = clock();
    delete pObj;
    double expected = 171.3220818815331;
    if(result == expected) {
        cout << "Test Case 23: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 0;
    } else {
        cout << "Test Case 23: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 1;
    }
}
Ejemplo n.º 6
0
int test22() {
    vector<int> eatenCandies = {1000, 245, 880, 676, 549, 945, 86, 987, 397, 793, 785, 408};
    AverageCandyLifetime* pObj = new AverageCandyLifetime();
    clock_t start = clock();
    double result = pObj->getAverage(eatenCandies);
    clock_t end = clock();
    delete pObj;
    double expected = 190.7308734356857;
    if(result == expected) {
        cout << "Test Case 22: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 0;
    } else {
        cout << "Test Case 22: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 1;
    }
}
Ejemplo n.º 7
0
int test21() {
    vector<int> eatenCandies = {0, 91, 181, 269, 356, 439, 519, 594, 665, 730, 789, 841};
    AverageCandyLifetime* pObj = new AverageCandyLifetime();
    clock_t start = clock();
    double result = pObj->getAverage(eatenCandies);
    clock_t end = clock();
    delete pObj;
    double expected = 258.5823894775301;
    if(result == expected) {
        cout << "Test Case 21: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 0;
    } else {
        cout << "Test Case 21: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 1;
    }
}
Ejemplo n.º 8
0
int test19() {
    vector<int> eatenCandies = {0, 8, 33, 74, 132, 207, 298, 405, 529, 669, 826, 1000};
    AverageCandyLifetime* pObj = new AverageCandyLifetime();
    clock_t start = clock();
    double result = pObj->getAverage(eatenCandies);
    clock_t end = clock();
    delete pObj;
    double expected = 291.79359005022724;
    if(result == expected) {
        cout << "Test Case 19: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 0;
    } else {
        cout << "Test Case 19: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 1;
    }
}
Ejemplo n.º 9
0
// BEGIN KAWIGIEDIT TESTING
// Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
bool KawigiEdit_RunTest(int testNum, vector <int> p0, bool hasAnswer, double p1) {
	cout << "Test " << testNum << ": [" << "{";
	for (int i = 0; int(p0.size()) > i; ++i) {
		if (i > 0) {
			cout << ",";
		}
		cout << p0[i];
	}
	cout << "}";
	cout << "]" << endl;
	AverageCandyLifetime *obj;
	double answer;
	obj = new AverageCandyLifetime();
	clock_t startTime = clock();
	answer = obj->getAverage(p0);
	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" << p1 << endl;
	}
	cout << "Your answer:" << endl;
	cout << "\t" << answer << endl;
	if (hasAnswer) {
		res = fabs(p1 - answer) <= 1e-9 * max(1.0, fabs(p1));
	}
	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;
}