Skip to main content
Logo image

Section 19.6 Bottom-Up Testing

When working on a small sub-sub-problem of a big program via a function it is important to test the function extensively before making it part of the bigger program.
To do so, one simply writes a so-called driver, that is, a main function whose purpose it is to call your new function in order to check whether if works correctly.
Suppose, for example, you are writing the function simplify() that simplifies a fraction. Here is a sample driver to test this function:
int main(void) {
  int numer = 50;
  int denom = 10;
  printf("original: %d/%d\n", numer, denom);
  simplify(&numer, &denom);
  printf("simplified: %d/%d\n", numer, denom);
}
There is no point in making this fancy: you’ll discard it later!

Investigate 19.4.

What should your driver do to the function you are testing?