Chapter 8: Testing Times
Mull It Over
Write a test harness for the
greatest_common_divisorcode example earlier in this chapter. Make it as exhaustive as you can. How many individual test cases have you included?How many of these passed?
How many failed?
Using these tests, identify any faults and repair the code.
There are a large number of tests you should run, even though there are very few invalid input combinations. Thinking of invalid inputs first: Test for zero. It may or may not be an invalid value (we’ve seen no spec, so we can’t tell), but you’d expect the code to cope reasonably with it.
Next, write tests considering combinations of usual inputs (say of 1, 10, and 100 in all orders). Then try numbers with no common multiple, like 733 and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access