One way to test short programs is to do what is known as a dry run using paper. A dry run involves creating what is called a trace table, containing all the variables a programSequences of instructions for a computer. contains. Whenever the value of a variable changes, the change is indicated in the trace table.
Consider this simple program:
1 total = 0
2 for count = 1 to 3
3 number = int(input("Enter number ", count))
4 total = total + number
5 next count
Each instructionA single action that can be performed by a computer processor. has been given a line number (1-5). The program has three variables - total, count and number – which will be put into a trace table.
Instruction
total
count
number
Instruction
total
count
number
Next, the program is tested using test data. If the numbers 5, 7 and 9 are inputted, the resulting total should be 21.
The instruction number is inputted. If a variable changes with that instruction, the new variable value is written in the appropriate box, as follows:
Instruction
total
count
number
1
0
2
1
3
5
4
5
5
2
2
3
7
4
12
5
2
3
3
9
4
21
5
Instruction
1
total
0
count
number
Instruction
2
total
count
1
number
Instruction
3
total
count
number
5
Instruction
4
total
5
count
number
Instruction
5
total
count
number
Instruction
2
total
count
2
number
Instruction
3
total
count
number
7
Instruction
4
total
12
count
number
Instruction
5
total
count
number
Instruction
2
total
count
3
number
Instruction
3
total
count
number
9
Instruction
4
total
21
count
number
Instruction
5
total
count
number
At each step, the programmer is able to see if, and how, a variable is affected.
Trace tables are extremely useful because they enable a programmer to compare what the value of each variable should be against what a program actually produces. Where the two differ is the point in the program where a logic error has occurred.