Make a Failure Useful
A bug is behavior that violates a stated rule. A test supplies an input, an expected result and a comparison. A traceback identifies where Python failed; the final exception explains the immediate failure, not necessarily its original cause.
Authored explanation · fixed examples, not a live experiment.
Rule: multiply quantity by price
→Counterexample (2, 3): expected 6, observed 5
→Repair operator, rerun old and new tests
Why does one passing example miss a bug? Name the evidence for your answer.
By the end of this lesson
Use a failing test and a minimal counterexample to repair a calculation.
Inside the lesson
- See why a test misses a bug
- Choose a counterexample
- Repair and test the function
- Explain your repair
- Test a different calculation
- Keep failures useful
The reproducibility tasks require running the supplied Python starter. Setup instructions and examples are included.