A calculation can return a plausible number and still be wrong. Tests compare the result with a stated rule. Debugging then locates the cause of a failed comparison. This lesson checks a return function with ordinary, boundary and invalid inputs. It also explains why numerical comparisons need a tolerance and why a fix should be recorded with its test in Git.
Learning objectives. By the end of this note you should be able to select normal, boundary and invalid cases; write small assertions; and isolate a failure before changing code.
In this lesson
- Test the contract
- Debug systematically
- A failed comparison needs a cause
Before you start
The full lesson, with worked examples and exercise solutions, is for members.
Read the full lessonNew to SelfMadeQuant.com? See membership options or browse the Python and Data Primer syllabus.