Test boundaries where an algorithm changes its behavior

← Back to Blog & Articles

Boundary cases are inputs near a decision point in the algorithm or in its contract. They often reveal mistakes that a typical middle-sized example leaves hidden.

Worked example

For a function that inserts a value into a sorted list, check insertion before the first item, after the last item, and next to an equal value. The equal-value case forces a decision about whether insertion happens before or after existing ties. For a range query, check an empty range and a range that ends exactly at the collection boundary.

What to check

Derive cases from the rules instead of choosing them only by intuition. Write the expected result before running the implementation. Tests can demonstrate that specific examples meet the contract, while invariants and proofs help explain why all supported inputs should behave correctly. When a test finds a failure, reduce the example until the transition that caused it is clear. That smaller input is usually easier to understand and retain as a regression check.

Continue with the book

Explore the full treatment, worked examples, and exercises in Algorithms Made Simple.


Companion article for Algorithms Made Simple, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.

Scroll to Top