Example #1
0
void TestFibonacciClosedForm(CuTest *tc) {
  int tests[] = {0,1,2,3,4,5,10,40};
  int expected[arraylen(tests)];
  int actual[arraylen(expected)];
  int len = arraylen(tests);
  for (int i = 0; i < len; i++) {
    int num = tests[i];
    expected[i] = fibonacciIterative(num);
    actual[i] = fibonacciClosedForm(num);
  }
  CuAssertStrEquals(tc,
                    IntArrayToString(expected, len),
                    IntArrayToString(actual, len));
}
Example #2
0
/* This function should call the fibonacci function a number of times, and write the
 * results to the file.
 * param	filename						name of the file to be opened
 * param	maxFibonacciNumToCompute		index of the max number to be computed
 * pre		maxFibonacciNumToCompute>0
 * post		a file exists, with fibonacci numbers 1-Max written in it.
 */
void testIterativeFibonacci(char* filename, int maxFibonacciNumToCompute)
{
	/* FIXME you will write this function */
	int nSum = 0, nNum = 0, i;

	FILE *iterative = fopen("iterative.txt", "w");
	fprintf(iterative, "The numbers: \n");
	fclose(iterative);

	for (i = 1; i <= maxFibonacciNumToCompute; i++)
	{
		nNum = fibonacciIterative(i);
		iterative = fopen("iterative.txt", "a+");
		fprintf(iterative, "%d\n", nNum);
		fclose(iterative);
		nSum += nNum;
	}

	iterative = fopen("iterative.txt", "a+");
	fprintf(iterative, "\n  The sum of %dth Fabonacii Number is : %d\n", maxFibonacciNumToCompute, nSum);
	fclose(iterative);
}