CS 200 - Lab 19


Your task is to implement and test the following functions

Information needed
Result computed
Return type
an integer
int value
value rounded to
nearest multiple of 100; e,g:

round_nearest_100(204) == 200
round_nearest_100(361) == 400
an integer
int value
true (1) if value is odd, false (0) if value is even
a double value
double x 3x2 + 6x + 12
a temperature
in Celsius
double tempC
temperature in Fahrenheit,
which is mathematically
equal to (tempC * 9/5) + 32

Just as you did in Lab 18, use the ASSERT_EQUALS function to check that each function computes the correct result for a particular input value.  Specifically, the first argument value should be the expected value, and the second should be a call to the function that you want to test.

The main function of your program should look something like this:

int main()
ASSERT_EQUALS(200, round_nearest_100(204));
ASSERT_EQUALS(400, round_nearest_100(361));
/* More tests here... */

printf("All tests passed\n");
return 0;

Each function should have at least 4 tests.

Getting Started

If you have a solution open in Visual Studio, close it (File->Close Solution).

Download lab19.zip.  Import it into Visual Studio (File->Import...).

Add your code to the source file called Functions.c.


Get one function and its tests completely working before proceeding to the next.

Try writing the tests for a function before writing the function itself.  You should try to write tests that differ from each other: for example, your tests for the is_odd function should include cases for all possible combinations of even/odd and positive/negative numbers.

For the functions returning a double value, the expected value should be computed using an expression that mimics the computation that the function your are testing will perform.  For example:

ASSERT_EQUALS( 3*(2.0*2.0) + 6*2.0 + 12, poly(2.0) );