Skip to content
IGCSE·Tuition

Study routes

Design a boundary test before editing code

You changed one symbol, the test you tried passed, and two days later the same kind of mistake showed up somewhere else.

On this page
  1. Why do errors gather at the edges?
  2. How to design the test
  3. Worked example
  4. The mistake to watch for
  5. Check yourself
  6. Where this leads next

To design a boundary test, find every edge in the rule, list the values just below, on and just above each edge, write what the rule says should happen, and only then run the code. The table is the test. The code is what you check against it.

Boundary tests catch the commonest small errors in selection and loops. They also give you evidence that a fix worked, instead of a feeling.

Why do errors gather at the edges?

Most of a rule’s range is unambiguous. A mark of 30 fails and a mark of 90 is an A under almost any version of the code. The difference between “greater than” and “greater than or equal to” only shows at the exact value.

So a test with comfortable values can pass while the code is wrong. The bug sits in the one place you did not look.

How to design the test

  1. Write the rule in plain words, including the valid range.
  2. Mark each edge where the outcome changes.
  3. List values just below, on and just above each edge, plus one typical value.
  4. Fill the expected column from the rule, before running anything.
  5. Run the code and fill the actual column.
  6. Fix the code, then rerun the whole table, not only the failed row.

Worked example

Rule: marks run from 0 to 100.

A mark of 80 or more gets “A”. A mark of 50 to 79 gets “Pass”. Below 50 gets “Fail”.

The code a student wrote:

def grade(mark):
    if mark > 80:
        return "A"
    elif mark > 50:
        return "Pass"
    else:
        return "Fail"

The edges are 50 and 80. The table:

MarkExpectedActualResult
0FailFailok
49FailFailok
50PassFailwrong
79PassPassok
80APasswrong
100AAok

Two rows fail, both exactly on an edge.

The cause is the same in both places: > should be >=. After changing both, rerun all six rows. All should now agree.

The mistake to watch for

A student sees that 50 gives the wrong result, changes that line and reruns only that row. It passes, so the student stops. The fault at 80 is still there.

A second version of the mistake is to test only 30, 65 and 90. All three pass with the broken code, so the student concludes the code is fine.

The correction: choose values from the edges, and rerun the complete table after every edit.

Check yourself

1. A rule says “child ticket if age is under 13”. Which values test the edge?

Show answer

12 (child) and 13 (not a child), and 14 as a value just above. The edge is at 13.

2. A rule says “pass if mark is at least 50”. Write the two most useful test values and their expected results.

Show answer

49 gives Fail and 50 gives Pass. Those two sit on either side of the edge.

3. With the broken grade code above, would testing 30, 65 and 90 reveal the bug?

Show answer

No. 30 gives Fail, 65 gives Pass and 90 gives A, all correct. Only 50 and 80 expose the fault.

Where this leads next

The lessons on designing normal, boundary and invalid test data and identifying an untested branch go further. To practise the first step, see creating a minimal reproducible learning example. You can run small original exercises in the safe Python reasoning sandbox.

When tests pass but you still cannot say why, one-to-one Computer Science tuition gives you a teacher to reason through the rule with. The Computer Science learning guide shows how testing fits into the subject.

Questions people ask

What is a boundary value?

It is a value at the edge of a rule, where the behaviour should change. For a pass mark of 50, the values 49 and 50 sit either side of the edge. Errors cluster there because a single symbol, such as greater than versus greater than or equal to, decides which side a value falls on.

Why write the test before changing the code?

Because the expected results should come from the requirement, not from what the code currently does. If you run the code first and copy its output, a wrong rule can look correct. Writing the expected column first keeps your judgement independent of the code.

How many test values do I need?

For each boundary, test the value just below, the value on it and, when helpful, the value just above. Add one typical value and any extreme value the rule mentions. Six to ten values are often enough for a small rule.

What about invalid input such as a mark of 101?

The requirement decides. If it says marks run from 0 to 100, the program needs a defined response to 101, such as rejecting it. If the requirement is silent, note that as a question to settle, not something to guess.

Sources

  1. Cambridge IGCSE Computer Science 0478 syllabus page

Updated:

Your next step

If you fix one bug and another appears at the edge of a rule, a one-to-one Computer Science teacher can help you build the test table first and explain each expected result with you.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80. Other fees, schedules and ongoing arrangements are confirmed directly with your teacher after the trial class.

9,000+ students helped through our service