< previous page page_889 next page >

Page 889
void PrintEntry( /* in */ EntryType entry,      // Friend's record
                 /* in */ DateType  birthday )  // Friend's birthday
                                                //   this year
// Prints the name, phone number, and birthday

// Precondition:
//         entry is assigned
// Postcondition:
//         entry.firstName, entry.lastName, entry.phone, and birthday
//         have been printed

{
    cout << entry.firstName <   < entry.lastName < endl;
    cout << ( < entry.phone.areaCode < ) 
         < entry.phone.number < endl;
    birthday.Print();
    cout << endl < endl;
}
Testing: The only portions of this program that need to be checked are the main function and the input and output routines. The operations on dates have already been tested thoroughly.
The GetEntry routine is nearly the mirror image of the output routine from the Friends program that created the address book, printing out exactly what was read in for the name and telephone number. The date is written out in a different format, but the class member function that writes the date has been tested already. Therefore, only the logic of the main function needs extensive testing.
The logic in the main function is straightforward. The test data should include birthdays less than two weeks away, exactly two weeks away, and more than two weeks away. The current date should include the cases where two weeks away is within the same month, within the next month, and within the next year.
Testing and Debugging
Testing and debugging a C++ class amounts to testing and debugging each member function of the class. All of the techniques you have learned aboutalgorithm walk-throughs, code walk-throughs, hand traces, test drivers, verification of preconditions and postconditions, debug outputs, the assert function, and the system debuggermay be brought into play.
Consider how we might test this chapter's TimeType class. Here is the class declaration, abbreviated by leaving out the function preconditions and postconditions:

 
< previous page page_889 next page >