Mark Seemann uses a budgeting exercise to test how one input change affects a result. With a fixed budget and positive charges, taking items out of an affordable bill should keep it affordable. QuickCheck, a Haskell library that generates test inputs, lets him check that rule across many bills and budgets.
- Generate a budget and a nonempty bill, then pick an item to remove.
- If the original bill was affordable, require the smaller bill to be affordable too.
- The existing code passed immediately. Seemann kept the property as possible groundwork for a later test.
A rule like this lets you test a relationship without calculating the right answer for every bill. Check how often your generated bills are affordable to begin with: those are the cases that actually exercise the rule.