< previous page page_237 next page >

Page 237
Neither of the then-clauses of the first two If statements are executed for this input data, so we do not fill in any of the variable columns to their right. We always create columns for all of the variables, even though we know that some will stay empty. Why? Because it's possible that we'll encounter an error that refers to an empty variable; having a column for the variable reminds us to check for just such an error.
When a program contains branches, it's a good idea to retrace its execution with different input data so that each branch is traced at least once. In the next section, we describe how to develop data sets that test each of a program's branches.
Testing Selection Control Structures
To test a program with branches, we have to execute each branch at least once and verify the results. For example, in the student warning notices program (Notices), there are four If-Then-Else statements (see Figure 5-7). We need a series of data sets to test the different branches. For example, we could use the following sets of data for the input values of test1, test2, and test3:
test1
test2
test3
Set 1
100
100
100
Set 2
60
60
63
Set 3
50
50
50
Set 4
-50
50
50

0237-01.gif
Branching Structure for Notices Program

 
< previous page page_237 next page >