Software Carpentry Day 8: Testing
Morning
The Nanotech example from last week
doesn't include any error checking.
- Make up half a dozen badly-formatted input files to share with
other students. Try to make some of the flaws in your files very
subtle.
- Add error handling to your copy of Nanotech. How useful can you make the error
messages? How many of the errors in your fellow students' files did
you fail to catch?
- The sample solution to Nanotech doesn't
contain any comments. How annoying is this? What kind of comments
would actually have been useful to remind you how the program
works?
Afternoon
- Using
unittest, write some tests for the functions in
the Nanotech example. If you want, you may
modify the functions (e.g., replace filenames with
CStringIO objects) in order to make things more
testable.
- Add three or four bugs (the subtler the better) to your copy of Nanotech and swap code with another team. How
many of your bugs are their tests able to find? How many of theirs
errors did yours find?
- Bhargan Bitdiddle wants to know the cost of molecules. At NanoCore
each atom costs its atomic number in cents. Write tests for a function
that receives a molecule and returns its cost in cents. Then write the
function, making each test pass in turn. Did your tests cover
independent aspects of the functionality? Are there tests that always
pass and fail together? Is there any part of the function left
untested? What happens if a molecule is empty or contains invalid
atoms?