First done in October, 2016 at a recruiting event.
Concept and "script" adapted from Uncle Bob's Bowling Game kata
$ bundle install --path .bundle
$ rspec # or run in RubyMine
The first attempt at running specs should fail as Game
is not defined.
Add the Game
class to the source file, but no methods. With this you should have all tests pending, but RSpec working.
"The simplest game is 20 gutter balls. So let's roll 20 of them and then ensure we have a score of zero."
- loop in the test to roll
- test for the score
- method for
#roll
- method for
#score
Get green with defaults.
"Now it's time to score. What's the simplest full game? All one pins."
- loop in the test to roll
- test for the score of 20
#roll
needs to save off the pins that are knocked down#score
should return the score
- extract a
@game
instance variable - extract a
rollMany
"Spares are complex. When you roll a ten with two pins, the next pin is counted as well."
roll(5)
roll(5)
roll(3)
roll_many
for the rest- expect score of 16
To make this work, #score
should be an action, not a getter. This is a good design discussion.
Save off all rolls into an array and then walk the array to score. Spares first, then not.
- extract
#is_spare?
"One roll, ten pins is a strike. The next two rolls count to the score."
roll(10)
roll(4)
roll(3)
roll_many
for the rest- expect score of 24
- Check for strike first
- extract
#is_strike?
- extract
#strike_bonus
- extract
#spare_bonus
- extract
#pins_in_frame
roll_many(12,10)
- expect score to be 300
This should just work. BOOM.