Boundary cases

A boundary case is an input at or beyond the edge of what a program normally handles. These cases expose assumptions that may remain invisible during ordinary use.

The cost analysis in Space complexity describes what grows, but not whether the behavior remains correct. Ask what happens at each edge of the help desk contract.

Common examples

  • An empty collection
  • A collection containing one item
  • The first or last valid index
  • The smallest or largest accepted number
  • Missing, duplicate, or null data
  • Invalid input
  • A very large collection
  • A request that fails halfway through

For the help desk, ask what happens when the event batch is empty, an ID is missing, an event is duplicated, a queue has no reports, two incidents share a priority, or a graph contains a cycle. The answer is part of the operation’s contract.

Finding boundary cases

Read the requirements for words such as “at least,” “no more than,” “optional,” and “must.” Then test values just below, at, and just above each limit. Document behavior that callers need to know.

Boundary cases should be considered while writing pseudocode, not only after a bug appears.