Specialty Digest

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

Online Courses / University Track / Computing Foundations

Module 1 · Lesson 4 · Core

Pseudocode, edge cases and testing

Write a method in plain structured text, then choose tests that expose its hidden faults.

  • 50 minutes
  • Serves O1 and O6
  • Assumes M1.L3

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 testExample inputWhy it matters
Typical4, 9, 2, 7The normal case works.
One item5The loop has nothing to compare.
All negative-8, -3, -6A start value of 0 would give the wrong answer.
Repeated values3, 3, 3Ties 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.

  1. Typical: 2, 4, 6 gives 4. (1 mark)
  2. One item: 5 gives 5. (1 mark)
  3. Empty list: the number of items is 0, so division is impossible. (1 mark)
  4. 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?

2. Which test best exposes a start value of 0 in the largest-number method?

3. Why test an empty list for an average?

4. What does a boundary case test?

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

MistakeWhy it fails
Testing only the typical caseFaults live at the edges.
Starting a stored value at an arbitrary numberStart from the first item.
Ignoring the empty inputThe 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.