Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Edge cases and boundary thinking

โญ beginnerโณ 12 min read๐Ÿ“ Lesson 68 of 85

Bugs live at the edges: empty, null, one, many, boundaries, and the values you didn't think of.

The edge taxonomy

For any function ask: what about โ€”

  • Empty โ€” no elements at all?
  • Null โ€” the absence of a collection, not the same as empty?
  • One โ€” a single element?
  • Many โ€” does it still work at scale?
  • Boundary โ€” exactly at the limit (<= vs < bugs live here)?
  • Weird โ€” duplicates, negative numbers, unicode, whitespace?
// the classic boundary bug
static bool IsAdult(int age) => age > 18;   // an 18-year-old disagrees!

Off-by-one errors concentrate at boundaries. When the spec says "18 or older", write the test for exactly 18 first.

Test both directions

An incorrect solution must fail โ€” that's what makes a test a test. For every claim, the two-sided habit: a case where correct code passes, and a near-miss implementation that must not. A test suite where anything passes proves nothing.

โšก Now practice

Ready to Code
Debugging workoutDiagnose broken helpers, fix boundary bugs, and write the discriminating tests yourself.
4 challenges ยท ยท ~40 min