Phase 1: Prepare
Step 1 Warm-up recall
From M3.L3: which branch runs for age 65?
Private: nothing you type here is sent or stored.
Step 2 Learning goal
By the end of this lesson you can:
- choose test inputs at boundaries (Foundation);
- find an off-by-one error (Core);
- correct a faulty condition (Core).
Phase 2: Teach
Step 3 A familiar example
Most mistakes in rules are not in the middle of a range; they sit exactly on the boundary, where “under 18” and “18 and over” meet.
Step 4 Clear explanation
A boundary is a value at which the answer changes. For each boundary, test the value on each side of it.
| Test age | Expected price (£) | Why test it |
|---|---|---|
| 4 | 0 | Last free age |
| 5 | 4 | First child price |
| 17 | 4 | Last child price |
| 18 | 8 | First adult price |
| 64 | 8 | Last adult price |
| 65 | 5 | First senior price |
An off-by-one error happens when a rule uses < instead of ≤, or > instead of ≥, so the boundary value falls on the wrong side. Consider this faulty chain: under 5 is free; under 17 costs £4; under 64 costs £8; otherwise £5. A 17-year-old gets the adult price of £8 (should be £4), and a 64-year-old gets the senior price of £5 (should be £8). The fix is to change 17 to 18 and 64 to 65. Boundary tests find such errors quickly, because they test exactly the values the rule gets wrong. The same idea applies to any programming language.
Step 5 Worked example (4 marks)
The faulty chain says under 17 costs £4. What does a 16-, 17- and 18-year-old pay, and which is wrong?
- Age 16: 16 < 17 is true, so £4 (correct). (1 mark)
- Age 17: 17 < 17 is false; next, 17 < 64 gives £8 (wrong, should be £4). (1 mark)
- Age 18: £8 (correct). (1 mark)
- The error is at the boundary: change < 17 to < 18. (1 mark)
Phase 3: Practise
Step 6 Learner practice (instant-marked)
1. A boundary is:
Test each side of it.
2. A rule changes at age 18. The best pair of boundary tests is:
Test either side of the boundary.
3. An off-by-one error is usually caused by using the wrong:
The boundary value falls on the wrong side.
4. In the faulty chain (under 17 pays £4), an age-17 person pays:
17 < 17 is false, so the next condition applies.
Phase 4: Close
Step 7 Recap
- Test the value on each side of every boundary.
- Off-by-one errors come from < versus ≤.
- Fix the comparison, then re-run all the boundary tests.
Step 8 Exit ticket (ungraded)
List six boundary tests for a rule that changes at ages 5, 18 and 65.
Private: nothing you type here is sent or stored.
Step 9 Go further (Extension)
Write a boundary test table for a password rule of at least 12 characters.
Common mistakes
| Mistake | Why it fails |
|---|---|
| Testing only typical values | Add the boundary values. |
| Testing only one side of a boundary | Test both sides. |
| Changing the rule without re-testing | Run all tests again after any change. |
Limits. Boundary tests are not proof that a rule is correct; they catch a common class of mistake.