Edge Cases & Determinism
intermediate13 min readLesson 92 of 180
The boundary checklist, order-blind assertions, and the regression-net habit after every bug fix.
Edge-case nets and determinism
An intermediate test suite hunts boundaries:
- empty / single / many โ the three sizes every collection behavior must satisfy
- zero, min, max โ numeric edges (0, Integer.MIN_VALUE, MAX_VALUE)
- first / last / middle โ position-sensitive logic
- duplicate and absent keys โ map semantics
- null vs empty vs blank โ three different "nothings"
// boundary net for a discount function
checkEq(discount(0), 0, "zero price");
checkEq(discount(1), 1, "minimal price");
checkEq(discount(Integer.MAX_VALUE), ..., "max price");
Determinism rules:
- never assert on unordered collections' toString (order is incidental)
- sort or compare as sets when order doesn't matter
- fixed seeds for randomness; frozen clocks for time
- a test that sometimes fails is worse than one that always fails โ fix or delete it today
Regression nets: when you fix a bug, add the test that would have caught it โ forever.