Specialty Digest

Global English editionLearners’ Study Dashboard — in development
The Knowledge Library for All

Online Courses / University Track / Computing Foundations

Module 3 · Lesson 4 · Core

Testing conditions at their boundaries

Choose test cases on either side of each boundary and find the classic one-off error.

  • 50 minutes
  • Serves O3
  • Assumes M3.L3

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.

4051172183644655Test each side of every boundary
The ages that matter most are those on either side of a boundary: 4 and 5, 17 and 18, 64 and 65.
Test ageExpected price (£)Why test it
40Last free age
54First child price
174Last child price
188First adult price
648Last adult price
655First 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?

  1. Age 16: 16 < 17 is true, so £4 (correct). (1 mark)
  2. Age 17: 17 < 17 is false; next, 17 < 64 gives £8 (wrong, should be £4). (1 mark)
  3. Age 18: £8 (correct). (1 mark)
  4. 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:

2. A rule changes at age 18. The best pair of boundary tests is:

3. An off-by-one error is usually caused by using the wrong:

4. In the faulty chain (under 17 pays £4), an age-17 person pays:

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

MistakeWhy it fails
Testing only typical valuesAdd the boundary values.
Testing only one side of a boundaryTest both sides.
Changing the rule without re-testingRun all tests again after any change.

Limits. Boundary tests are not proof that a rule is correct; they catch a common class of mistake.