< previous page page_447 next page >

Page 447
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Driver A simple main function that is used to call a function being tested. The use of a driver permits direct control of the testing process.
By surrounding a module with a driver and stubs, you gain complete control of the conditions under which it executes. This allows you to test different situations and combinations that may reveal errors. For example, the following program is a driver for the FuelMoment function in the Starship program. Because FuelMoment doesn't call any other functions, no stubs are necessary.
//******************************************************************
// FuelMomentDriver program
// This program provides an environment for testing the
// FuelMoment function in isolation from the Starship program
//******************************************************************
#include <iostream.h>

const float LBS_PER_GAL = 6.7;

float FuelMoment( int );

int main()
{
    int testVal;    // Test value for fuel in gallons

    cout << Fuel moment for gallons from 10 through 565
         <<  in steps of 15: << endl;
    testVal = 10;
    while (testVal <= 565)
    {
        cout << FuelMoment (testVal) << endl;
        testVal = testVal + 15;
    }
    return 0;
}

//******************************************************************

float FuelMoment( /* in */ int fuel )    // Fuel in gallons
{
    float fuelWt;           // Weight of fuel in pounds
    float fuelDistance;     // Distance from front of plane

 
< previous page page_447 next page >