Big software houses split tasks amongst various staff.
This unit will look at the job of the test engineers. This is the link between the algorithm engineers and the actual coders. Their job is critical to the success of a project.
An accountancy firm requires software that will allow a user to input tax data and output the total tax entered, the average tax, the number of tax data items entered. The program will terminate when the user enters -1.
An Algorithm engineer has produced the following pseudocode to solve the problem:
total ← 0
count ← 0
OUTPUT "Enter a tax amount: "
taxAmount ← USERINPUT
WHILE taxAmount <> -1 DO
total ← total + taxAmount
count = count + 1
OUTPUT "Enter a tax amount: "
taxAmount ← USERINPUT
END WHILE
average = total/count
OUTPUT "Total tax is ", total
OUTPUT "Average tax is ", average
OUTPUT "Number of tax items entered", count
To test this sequence of steps, the Test Engineers have identified the following test data to be input into the algorithm:
| 10 | 5 | 7 | 15 | 13 | 20 | -1 |
|---|
According to this data, they have already calculated their own actual results:
| Total | Count | Average |
|---|---|---|
| 70 | 6 | 11.67 |
In order to see how the algorithm manages the test data, a trace table can be used.
A trace table lists all of the variables used in the algorithm, and traces their values as each step in the algorithm is processed.
Here is an example of a trace table for the algorithm design above:
| total | count | taxAmount | average | "Total tax is " | "Average tax is " | "Number of items " |
|---|---|---|---|---|---|---|
| 0 | 0 | 10 | ||||
| 10 | 1 | 5 | ||||
| 15 | 2 | 7 | ||||
| 22 | 3 | 15 | ||||
| 37 | 4 | 13 | ||||
| 50 | 5 | 20 | ||||
| 70 | 6 | -1 | ||||
| 11.67 | 70 | 11.67 | 6 |
Let's take a closer look at what's going on.
| 10 | 5 | 7 | 15 | 13 | 20 | -1 |
|---|
total ← 0
count ← 0
OUTPUT "Enter a tax amount: "
taxAmount ← USERINPUT
WHILE taxAmount <> -1 DO
total ← total + taxAmount
count = count + 1
OUTPUT "Enter a tax amount: "
taxAmount ← USERINPUT
END WHILE
average = total/count
OUTPUT "Total tax is ", total
OUTPUT "Average tax is ", average
OUTPUT "Number of tax items entered", count
| total | count | taxAmount | avg | "Total" | "Average" | "Num items " |
|---|---|---|---|---|---|---|
| 0 | 0 | 10 | ||||
| 10 | 1 | 5 | ||||
| 15 | 2 | 7 | ||||
| 22 | 3 | 15 | ||||
| 37 | 4 | 13 | ||||
| 50 | 5 | 20 | ||||
| 70 | 6 | -1 | ||||
| 11.67 | 70 | 11.67 | 6 |