Testing functions you have written
18-minute lesson · module-testing-02
You are previewing this course as a guest
Read anything and run any exercise you like. It all runs in your own browser, so nothing here is saved: no XP, no progress, and the AI tutor needs an account. Sign in and your work starts counting.
Testing functions you have written
18-minute lesson · module-testing-02
- Collect several asserts into a single test function.
- Return a clear success signal when all checks pass.
- Choose test cases that cover normal, boundary, and tricky inputs.
- Run the function under test and its test function together.
Source attribution
Status: adapted
How to Think Like a Computer Scientist: Interactive Edition — source · Unit Testing / Testing Functions / Designing Testable Functions
Adaptation notes. Reading rewritten in our voice. The palindrome example is ours. The student writes BOTH the function under test and a run_tests() that asserts several cases and returns True; the hidden test calls run_tests() and also spot-checks the function directly.
License notes. Original chapter is GNU FDL 1.3 (Brad Miller, David Ranum, and the upstream Elkner/Downey/Meyers text). No verbatim text reproduced.