Spec & Goals 3 min
AQA Spec 3.2.11 · Robust and secure programming
By the end of this lesson you can:
- Explain why testing makes a program robust.
- Choose normal, boundary and erroneous test data for an input.
- State the difference between a syntax error and a logic error.
Warm-Up 5 min
Last lesson you wrote validation to reject silly input. Today we test a program to prove it actually works.
Quick starter
A program should accept exam marks from 0 to 100. Which single value is most likely to expose a bug at the edge?
5010072
Reveal the answer
100 — it sits right on the edge of what is allowed. Edge values catch "off-by-one" mistakes.
Key Concept — testing and kinds of test data 14 min
Testing runs a program with chosen data to find errors. A well-tested program is robust — it copes with unexpected input without crashing.
Three kinds of test data
For any input you should test all three kinds. They catch different mistakes.
| Test data | What it is |
|---|---|
| Normal | Typical, valid data the program should accept. |
| Boundary | Values at the very edge of what is allowed (still accepted). |
| Erroneous | Invalid data the program should reject. |
Syntax errors vs logic errors
Two very different kinds of error:
| Error | Effect | Example |
|---|---|---|
| Syntax error | Program will not run / translate. | Missing a colon or a bracket. |
| Logic error | Runs, but the output is wrong. | Using + where you meant −. |
A trace table records each variable as the program runs. It is the best tool for hunting a logic error.
Worked Example — test data and a trace table 12 min
Problem: a program accepts a test mark that must be in the range 0–100. Choose test data for it.
| Kind | Value(s) | Expected result |
|---|---|---|
| Normal | 57 | Accepted |
| Boundary | 0 and 100 | Accepted (on the edge) |
| Erroneous | -1 and 150 | Rejected |
Now a buggy routine that should total marks 1, 2 and 3 (answer should be 6):
01 total ← 0 02 FOR i ← 1 TO 3 03 total ← total + i 04 ENDFOR 05 total ← total + 1 06 OUTPUT total
Trace it to find the logic error:
| Line | i | total | Output |
|---|---|---|---|
| 01 | — | 0 | |
| 03 | 1 | 1 | |
| 03 | 2 | 3 | |
| 03 | 3 | 6 | |
| 05 | 3 | 7 | |
| 06 | 3 | 7 | 7 |
The loop already gives 6. Line 05 wrongly adds 1 more, so the output is 7. Removing line 05 fixes the logic error.
The corrected loop in Python
total = 0 for i in range(1, 4): total = total + i print(total)
This corrected version outputs 6 — the loop alone gives the right total.
Try It Yourself 12 min
Goal: Give one normal value for an input that accepts a month number 1–12.
Hint: any typical value inside the range works.
Goal: For an input that accepts a percentage 0–100, give one boundary value and one erroneous value.
Hint: boundary sits on the edge; erroneous sits outside it.
Goal: Decide whether each is a syntax or logic error: (a) a missing ENDIF; (b) a program that always outputs 'Fail' even for 90%.
Hint: ask whether the program would run at all.
📝 Exam Practice 10 min
Answer the way the examiner expects — the command word and the marks tell you how much to write.
An input accepts ages from 11 to 16. Give one normal, one boundary and one erroneous test value.
Mark scheme
- Normal: any value 12–15, e.g.
13(1). - Boundary:
11or16(1). - Erroneous: any value outside the range, e.g.
10or17(1).
State the difference between a syntax error and a logic error.
Mark scheme
- A syntax error breaks the rules of the language, so the program will not run (1).
- A logic error runs but produces the wrong result / output (1).
A field accepts a shoe size from 3 to 12. Identify the kind of test data for the value 12, and for the value 20.
Mark scheme
12— boundary data (on the edge of the allowed range) (1).20— erroneous data (outside the allowed range) (1).
Recap & Key Terms 3 min
Testing finds errors using normal, boundary and erroneous data. A syntax error stops the program running; a logic error gives a wrong result. A trace table helps locate logic errors.
- Testing
- Running a program with planned data to find errors and check it works.
- Normal test data
- Typical, valid data the program should accept.
- Boundary test data
- Values at the edge of the allowed range, which should still be accepted.
- Erroneous test data
- Invalid data the program should reject.
- Syntax error
- An error that breaks the rules of the language, so the program will not run.
- Logic error
- An error where the program runs but produces the wrong result.
Homework 1 min
Task (≤ 15 min): A field accepts a day of the month from 1 to 31. Give one normal, two boundary and two erroneous test values, and say what should happen to each.
Model answer
| Kind | Value(s) | Expected result |
|---|---|---|
| Normal | 15 | Accepted |
| Boundary | 1 and 31 | Accepted |
| Erroneous | 0 and 32 | Rejected |
Award marks for: a correct normal value (1), correct boundary values (1), correct erroneous values rejected (1).