Project 4 Extra Notes

Quick Hints and Reminders

  1. Do not copy the interface (.h) file into your account. You should use the path to the original in your code. Because the interface file will not change, you do not need to include it in your makefile.
  2. You absolutely cannot use operator== to compare against NAN (technically you can for INFINITY)
  3. Use “finite” as shown in the demo program to test for NAN and INFINITY
  4. To return NAN and INFINITY, write the names in all caps.
  5. You need to use symbolic constants (for PI, epsilon, etc.) either from the cmath library or created by yourself.

Incremental Development

  1. Some of the functions depend on other functions. Therefore, there is no point in writing the dependent functions until the functions they rely on are working.
  2. For some functions, it will be hard to handle all possible input values on your first attempt. For example, "modulo" must handle negative values, and in the same way that "fmod" from cmath does. First, get it to work just for positive values.

Testing Principles

This is the first project with a “driver” module for testing. You will need many test cases for each function.
Test cases fall into two categories:
  1. Error conditions (where output is undefined)
  2. Normal conditions

Testing Modules ("Drivers")

Absolutely required:
  1. You must label your output. It must be clear what the function, input, and output are.
  2. You must format it so that it is easy to read -- break the output into sections for each function\

At the very minimum, you will need to do something like this for every test:

cout << "factorial(" << 15 << ") = " << factorial(15) << endl;

Recommended (for now):
  1. You should compare the output of your functions with output from the “cmath” library. Otherwise, you're just guessing that the results are correct.
  2. You can use "setw()" from "iomanip" to create columns. Note that you must use "setw()" before every field individually.

Testing Functions

You will find it massively helpful to create auxiliary testing functions like this:

void testFactorial(int x) {
  cout << "factorial(" << x << ") = " << factorial(x) << endl;
}

Then, you can just call these auxiliary functions repeatedly in order to test your library functions, rather than
copying and pasting the whole output line.


Last edited 2/5/13