Case Study: Testing above_freezing
The first function that we’ll test is above_freezing from Testing Your Code Semiautomatically:
| def above_freezing(celsius): |
| """ (number) -> bool |
| |
| Return True iff temperature celsius degrees is above freezing. |
| |
| >>> above_freezing(5.2) |
| True |
| >>> above_freezing(-2) |
| False |
| """ |
| |
| return celsius > 0 |
In that section, we ran the example calls from the docstring using doctest. But we’re missing a test: what happens if the temperature is zero? In the next section, we’ll write another version of this function that behaves differently at zero and we’ll discuss how our current set of tests is incomplete.
Choosing Test Cases for above_freezing
Before writing our testing code, we ...
Get Practical Programming, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.