The Knowledge Institute
← Back to library

Programming Foundations · 1 MIN READ

Test the boundary in a program decision

A condition turns a verbal rule into a precise choice; equality often reveals a mistake.

Translate the rule before the code

Suppose a fictional shop offers free delivery when a basket subtotal is at least 50 dollars. The condition subtotal >= 50 includes equality; subtotal > 50 excludes it. An if statement chooses a branch according to its condition. Decide what the rule means before choosing the operator. Ask whether the threshold applies before or after discounts and whether delivery is available in the customer’s area.

Worked example: three baskets

Test subtotals of 49, 50, and 51. Under the stated rule, the first basket pays delivery and the other two qualify. Under the mistaken condition subtotal > 50, the 50-dollar basket pays delivery too. Testing only 60 dollars would miss the defect because both versions qualify that basket. The boundary case distinguishes the intended rule from a plausible implementation error.

Separate invalid input from a valid decision

A missing subtotal is not the same as a zero-dollar subtotal. Validate incoming data before applying the rule. If several conditions must hold, write their relationship explicitly: threshold met AND delivery area supported. If there are exceptions, specify their priority. A program can apply a rule consistently even when the rule itself is incomplete, unfair, or unsuitable; testing behavior does not settle policy.

Put it to work

Write three test inputs for a rule that accepts ages 18 and above. Then add a missing-input case and state its expected handling.

Knowledge check

1. Which operator matches “at least 50”?
2. Which input best distinguishes > 50 from >= 50?

Sources & further reading