Refactor to use state pattern for running test cases.

Closes #17

Note that I've added a TODO. Simplifying the code like this exposed some
holes in the logic that I think we'll need to cover off.