O'Reilly logo

Code Craft by Pete Goodliffe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8: Testing Times

Mull It Over

  1. Write a test harness for the greatest_common_divisor code example earlier in this chapter. Make it as exhaustive as you can. How many individual test cases have you included?

    1. How many of these passed?

    2. How many failed?

    3. 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required