Phase 1: Prepare
Step 1 Warm-up recall
From M1.L3: write what a trace table has one row of and one column of.
Private: nothing you type here is sent or stored.
Step 2 Learning goal
By the end of this lesson you can:
- write a short algorithm in pseudocode (Foundation);
- name typical, boundary and empty test cases (Core);
- find a fault by choosing a test that exposes it (Core).
Phase 2: Teach
Step 3 A familiar example
A lift is tested with one passenger, but the first full load of people finds the fault. A method needs tests at the edges, not only in the middle.
Step 4 Clear explanation
Pseudocode is a method written in plain, structured text that is not tied to any programming language. A typical version of the largest-number method reads: set largest to the first item; for each remaining item, if the item is greater than largest, set largest to the item; output largest. Because it is not tied to a programming language, a reader can check the logic first and translate it later.
A method is not correct because it works on one example. You need a set of tests. Include a typical case, boundary cases (the smallest and largest valid inputs) and any input the specification excludes or leaves open.
| Kind of test | Example input | Why it matters |
|---|---|---|
| Typical | 4, 9, 2, 7 | The normal case works. |
| One item | 5 | The loop has nothing to compare. |
| All negative | -8, -3, -6 | A start value of 0 would give the wrong answer. |
| Repeated values | 3, 3, 3 | Ties must not break the method. |
| Empty list | (nothing) | There is no largest item: the specification must say what happens. |
A common fault is to start the stored value at a fixed number such as 0 rather than at the first item. The list -8, -3, -6 then returns 0, which is not in the list. A test with all negative values exposes it. Choosing tests that could fail is the skill; choosing tests that pass proves little.
Step 5 Worked example (4 marks)
A method for the average of a list is: add all items, then divide by the number of items. Choose tests.
- Typical: 2, 4, 6 gives 4. (1 mark)
- One item: 5 gives 5. (1 mark)
- Empty list: the number of items is 0, so division is impossible. (1 mark)
- Repair: the specification must say what to do for an empty list, for example “output no result”. (1 mark)
Phase 3: Practise
Step 6 Learner practice (instant-marked)
1. What is pseudocode?
Pseudocode lets you check the logic before writing real code.
2. Which test best exposes a start value of 0 in the largest-number method?
With all negatives, 0 would wrongly be returned.
3. Why test an empty list for an average?
Division by zero shows the specification must handle emptiness.
4. What does a boundary case test?
Boundaries are where faults often hide.
Phase 4: Close
Step 7 Recap
- Pseudocode lets you check logic before coding.
- Test typical, boundary and empty cases.
- Choose tests that could fail.
Step 8 Exit ticket (ungraded)
List three tests for a method that returns the smallest number in a list.
Private: nothing you type here is sent or stored.
Step 9 Go further (Extension)
Write the pseudocode for the smallest-number method and trace your three tests on it.
Common mistakes
| Mistake | Why it fails |
|---|---|
| Testing only the typical case | Faults live at the edges. |
| Starting a stored value at an arbitrary number | Start from the first item. |
| Ignoring the empty input | The specification must say what happens. |
Limits. Testing can show a fault but cannot prove a method correct for every input. Later modules return to this limit.