Next: Series Minimum and Maximum Up: Verifying the correctness of Previous: Verifying the correctness of

Desk-checking

Another way of testing the logic of programs is to carry out a desk-check, that is execute the statements of the algorithm yourself on a sample data set. This method of course is not foolproof, you would have to be sure that you traversed all possible paths through your algorithm, this might require you to use many data sets. It is useful to use a tabular layout for this. For example say the initial data file was

2 6 eof
then a tabular layout as follows could be used:
 file    number count total average

2 6 eof                            before initialisation

*
2 6 eof           0     0          after initialisation

  *
2 6 eof    2      1     2          after first loop execution

     *
2 6 eof    6      2     8          after second loop execution

     *
2 6 eof    6      2     8     4    exit loop, evaluate average

The * indicates the file element which is available for reading on the next input statement. Obviously this gives the correct result for this file. This simple file is adequate to check the general case here because there are only two paths through this algorithm. The other path is the case where the file is empty. This could be checked in the same way.



Next: Series Minimum and Maximum Up: Verifying the correctness of Previous: Verifying the correctness of