Code
Write property-based tests
Generate the inputs nobody thinks of, and shrink the failure to something readable.
Fill it in
The module or function.
The invariants, in your words.
Report the smallest input that breaks it.
Your prompt
Write property-based tests for [your what to test]. Invariants: [your what must always hold] Find the properties that must hold for ALL inputs, not examples. Round-trip (parse then format returns the original), invariants (the total never goes negative), and comparisons against a slow obvious implementation are the three that find real bugs. Generate the inputs nobody writes by hand: empty, one element, duplicates, unicode, the boundary, one past it, and the value that is technically valid and absurd. That is the entire advantage over example-based tests. Shrink failures to the smallest reproducing input, and report it as a plain example test. A 400-character generated string that fails is a bug report nobody acts on; `add(0.1, 0.2)` is one somebody fixes today. Run enough cases to mean something, with a fixed seed so a failure reproduces.
Use Write property-based testsOpens with everything above already filled in.
Why this works
A 400-character generated string that fails is a bug report nobody acts on. This shrinks to the smallest reproducing input and reports it as a plain example, and it generates the inputs nobody writes by hand, which is the entire advantage over example tests.