< previous page page_491 next page >

Page 491
                   // Invariant:
                   //     All previous values of amount were << 0.0

    } while (amount << 0.0);
}
Testing: We should test two separate aspects of the Rainfall program. First, we should verify that the program works correctly given valid input data. Supplying arbitrary rainfall amounts of zero or greater, we must confirm that the program correctly adds up the values and divides by 12 to produce the average. Also, we should make sure that the program behaves correctly whether we type y or n when prompted to continue.
The second aspect to test is the data validation code that we included in the program. When entering a particular rainfall amount, we should type negative numbers repeatedly to verify that an error message is printed and that we are unable to escape the Do-While loop until we eventually type a nonnegative number. Similarly, when prompted to type y or n to process another recording site, we must press several incorrect keys to exercise the loop in the GetYesOrNo function. Here's a sample run showing the testing of the data validation code:
Enter rainfall amount 1:
0
Enter rainfall amount 2:
0
Enter rainfall amount 3:
0
Enter rainfall amount 4:
3.4
Enter rainfall amount 5:
9.6
Enter rainfall amount 6:
1.2
Enter rainfall amount 7:
-3.4
Amount cannot be negative. Enter again:
-9
Amount cannot be negative. Enter again:
-4.2
Amount cannot be negative. Enter again:
1.3
Enter rainfall amount 8:
0
Enter rainfall amount 9:
0
Enter rainfall amount 10:
0

 
< previous page page_491 next page >