|
|
|
|
|
|
|
<< calculations for fuel are approximate. If << endl
<< the aircraft is loaded near its limits, the << endl
<< pilot's operating handbook should be used << endl
<< to compute weight and center of gravity << endl
<< with more accuracy. << endl;
} |
|
|
|
|
|
|
|
|
Testing: Because someone could use the output of this program to make decisions that could result in property damage, injury, or death, it is essential to test the program thoroughly. In particular, it should be checked for maximum and minimum input values in different combinations. In addition, a wide range of test cases should be tried and verified against results calculated by hand. If possible, the program's output should be checked against sample calculations done by experienced pilots for actual flights. |
|
|
|
|
|
|
|
|
Notice that the main function neglects to guarantee any of the function preconditions before calling the functions. If this program were actually to be used by pilots, it should have data validation checks added in function GetData. |
|
|
|
|
|
|
|
|
One of the advantages of a modular design is that you can test it long before the code has been written for all of the modules. If we test each module individually, then we can assemble the modules into a complete program with much greater confidence that the program is correct. In this section, we introduce a technique for testing a module separately. |
|
|
|
|
|
|
|
|
Suppose you were given the code for a module and your job was to test it. How would you test a single module by itself? First of all, it must be called by something (unless it is the main function). Second, it may have calls to other modules that aren't available to you. To test the module, you must fill in these missing links. |
|
|
|
|
|
|
|
|
When a module contains calls to other modules, we can write dummy functions called stubs to satisfy those calls. A stub usually consists of an output statement that prints a message like, Function such-and-such just got called. Even though the stub is a dummy, it allows us to determine whether the function is called at the right time by the main function or another function. |
|
|
|
|
|