Course 7.2Lesson 3 of 3
A program is tested with data chosen on purpose. You learn the four kinds of test data in the syllabus: normal, abnormal, extreme and boundary. Then you use dry runs and test data to find errors in algorithms and to suggest how to correct them.
Try the code and the simulations beside the lesson.
When you check a calculator, you do not only try . You also try a very large number, a negative number and a division by zero. The aim is to find out where it goes wrong. Testing a program is the same. You choose test data, write down the result you expect, run the program and compare.
Take a program that accepts the number of tickets in an order: whole numbers from to .
Extreme data tests the very edge of what is allowed. Boundary data tests both sides of the edge. Many errors sit exactly at a boundary, for example > written where >= was needed.
A test is written as a row of a test plan: the kind of data, the value, and the expected result.
The syllabus asks you to find the errors in a given algorithm and to suggest a correction. Dry-run it with simple test data, and compare the result with what it should be. This algorithm should input five numbers and output their total.
Total ← 0
FOR Count ← 1 TO 5
INPUT Number
Total ← Number
NEXT Count
OUTPUT TotalTry the inputs , , , and . The total should be , but the algorithm outputs . A trace table shows why: Total takes the value of each number in turn, so only the last one is left. The line Total ← Number should be Total ← Total + Number.
Errors you will often meet in exam algorithms:
Highest ← 100 before looking for a highest value;< instead of >, or > instead of >=;1 TO 4 for five inputs;INPUT inside a loop.When you suggest a correction, write the whole corrected line in pseudocode, not just a description.
This Python program runs a whole test plan. Each test gives the kind of data, the input and the expected result. The program prints pass when the result matches. You met isinstance and lists of pairs in the Python Essentials book.
IF Mark > Highest.Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Largest ← 100. What goes wrong, and what is a correction?IF Quantity > 1 AND Quantity <= 50. Which test value shows the error?Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place in the course.