Skip to content
IGCSE·Tuition
Computer Science · Help with common difficulties

My program runs but fails a boundary case

Your program gives the right answer for the examples you tried, then gives the wrong one for the value sitting exactly on the edge.

On this page
  1. What does a boundary bug look like?
  2. How do I fix it?
  3. How do I choose boundary test data?
  4. A second example: “more than” and “at least”
  5. Words that signal an inclusive or exclusive edge
  6. A checklist before you submit a condition
  7. Where to go next
  8. When self-checking is not enough

A program fails at a boundary when its condition treats the edge value differently from what the problem says. The usual cause is < where <= is needed, or > where >= is needed. The fix is to choose boundary test data before you write the condition.

Below is one worked example with a trace table, then a second short one. Notation is simple pseudocode. Your route may use a specific style, so confirm it on the Cambridge page.

What does a boundary bug look like?

A school system should accept a test mark from 0 to 100 inclusive. Here is the first attempt.

INPUT Mark
IF Mark > 0 AND Mark < 100 THEN
    OUTPUT "Accepted"
ELSE
    OUTPUT "Rejected"
ENDIF

Try a few values. A student tests 50 and 75, sees “Accepted” for both and moves on. Now trace a fuller set.

MarkMark > 0Mark < 100OutputExpected
50TRUETRUEAcceptedAccepted
0FALSETRUERejectedAccepted
1TRUETRUEAcceptedAccepted
99TRUETRUEAcceptedAccepted
100TRUEFALSERejectedAccepted
−1FALSETRUERejectedRejected
101TRUEFALSERejectedRejected

Two rows fail: 0 and 100. Both are real marks that the program wrongly rejects. The ordinary tests never reached them.

How do I fix it?

Include the limits in the condition.

IF Mark >= 0 AND Mark <= 100 THEN

Re-trace the failing rows. Mark = 0 gives TRUE and TRUE, so Accepted.

Mark = 100 gives TRUE and TRUE, so Accepted. Mark = −1 gives FALSE, Rejected.

Mark = 101 gives FALSE on the second test, Rejected. All seven rows now match.

How do I choose boundary test data?

For a range with lower limit L and upper limit U, both inclusive:

PurposeValues (L = 0, U = 100)
On the lower limit0
Just inside the lower limit1
Just outside the lower limit−1
On the upper limit100
Just inside the upper limit99
Just outside the upper limit101

Write the expected result before you run anything. If you choose the expected result after seeing the output, the program is marking its own homework.

A second example: “more than” and “at least”

A shop gives free delivery when the order total is at least RM50. The code is:

IF Total > 50 THEN
    Delivery ← 0
ELSE
    Delivery ← 5
ENDIF
TotalCode givesCorrect
49.9055
50.0050
50.1000

Only the boundary value 50.00 exposes the fault. The words “at least” mean 50 is included, so the condition should be Total >= 50.

Words that signal an inclusive or exclusive edge

WordingCondition
at least 50, 50 or more, from 50Total >= 50
more than 50, over 50Total > 50
at most 50, up to and including 50Total <= 50
fewer than 50, under 50Total < 50

Underline the wording in the question and choose the symbol from this table, not from habit.

A checklist before you submit a condition

  1. Circle the limits in the question and decide if each one is inclusive.
  2. Write your boundary values and the expected result of each.
  3. Trace the two or three edge values through the condition by hand.
  4. Include one value outside each limit, and one abnormal input.
  5. Re-read: does the symbol match the wording?

Use the restricted pseudocode trace trainer to step through an original algorithm, and the safe Python reasoning sandbox to see a failing test with an explanation prompt, where your route allows it.

Where to go next

The full topic is in validation, verification and testing. If loops are also giving you trouble, read my loop runs forever or misses the last item. The original practice set has a test-data question, and the learning guide shows where it fits.

When self-checking is not enough

If you trace the edge values and still write the wrong symbol under time pressure, the gap is often in how you read the wording. A teacher can give you short, varied questions and listen to how you decide. Online one-to-one Computer Science tuition starts with a paid one-hour trial at the assigned teacher’s confirmed rate, from RM80.

Questions people ask

What is a boundary case?

It is a value at the exact edge of what the program accepts or treats differently. If a range is 0 to 100 inclusive, the boundary values are 0 and 100, and the values just outside are -1 and 101. Conditions go wrong most often at these values, because < and <= differ only there.

What test data should I choose?

Choose three kinds. Normal data is valid and typical. Boundary data sits on the edges, with values just outside them. Abnormal data should be rejected, such as text where a number is expected. For each item, write down the output you expect before running the program.

What is the difference between < and <=?

The < symbol excludes the value and <= includes it. A condition Mark < 100 rejects exactly 100, while Mark <= 100 accepts it. Always ask whether the edge value should count, then pick the symbol that matches the question.

Does the same idea apply to validation questions in the exam?

Yes. Questions on range checks and test data often depend on whether the limits are inclusive. Read the wording carefully, such as 'from 0 to 100' or 'more than 50', and choose test values on and around each limit.

Sources

  1. Cambridge IGCSE Computer Science 0478 syllabus page

Updated:

Your next step

If your code passes your own tests and still loses marks at the edges, a teacher working one to one can help you build the habit of choosing test data before writing the condition.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80. You agree the teacher’s hourly rate before the trial, and ongoing lessons continue at that same rate. The schedule is arranged with your teacher after the trial.

Tuition is arranged with a parent or guardian. Send them this page on WhatsApp and they can enquire for you.

Parent or guardian? Enquire here

9,000+ students helped through our service