# Lab 20: More functions, Testing

## Getting Started

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

Name Information needed Parameters Result computed Return type
round_nearest_100 an integer value int value

value rounded to nearest multiple of 100; e,g:

round_nearest_100(204) == 200

round_nearest_100(361) == 400

int
is_odd an integer value int value true (1) if value is odd, false (0) if value is even int
poly a double value double x 3x 2 + 6x + 12 double
celsuis_to_fahr a temperature in Celsius double tempC temperature in Fahrenheit, which is mathematically equal to (tempC * 9/5) + 32 double

Just as you did in Lab 19, 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.

## Hints

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) );

## Submitting

When you are done, choose Tools->Submit to submit your completed lab to the server. You will need to enter your Marmoset username and password.

If the Tools->Submit option does not work, create a zip file containing the files in your project, and upload it to the submission server as lab20. The server URL is

https://camel.ycp.edu:8443/