I didn’t comment out all the tests, but instead
tried to make them green in order, following the philosophy of trying
to do it in a correct way rather than simply “return 5” or
whatever to make a test pass. A side effect is, for example, trying
to make T02 pass actually failed my first attempt, but the attempt
caused T03 and T05 to pass, so I made a commit for that (so the
commits are for tests passing out of the order I was actually trying
to make them pass).
So, I decided to commit every modification that
made new tests pass, whatever they were. My first commit was to make
T01Bowl23 pass, and that was this basic framework code that I thought
might be extendable to a full scoring code: it’s essentially a
state machine:
After that, it’s commits to github:
starting with Make T01Bowl23 Pass, hash code starts with 021e487.
When I got to T07BowlX1 is when it become
difficult. My first attempt made tests 12 and 21 pass, but when I
fixed the bug, they failed again but test 7 still didn’t pass, so I
realized the methodology was flawed and had to start rethinking.
After a half hour, including walking away, it hit
me: dump the state machine model and keep an array of number of balls
needed for each frame. Doing that, and fixing a few minor issues
while doing so, yielded this code:
Fixing some bugs caused all tests up to T17 to pass, as well as T19 and
TG03GoldenCopyB2of3. So, now time to handle that special tenth
frame.
Simply not advancing frame count beyond 10 caused TG03GoldenCopyB1of3 and
TG03GoldenCopyB3of3, and T20 to pass.
Getting rid of “startOfFrame” and instead
counting “ballsThisFrame” and separating cases 1, 2, and other
caused all tests to pass: