diff --git a/files/Bowling Game Kata.pdf b/files/Bowling Game Kata.pdf new file mode 100644 index 0000000..b399075 Binary files /dev/null and b/files/Bowling Game Kata.pdf differ diff --git a/spec/bowling_game_spec.rb b/spec/bowling_game_spec.rb new file mode 100644 index 0000000..27848ed --- /dev/null +++ b/spec/bowling_game_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe BowlingGame do + + before(:each) do + @game = BowlingGame.new + end + + it "should calculate a gutter game" do + roll_many(20, 0) + @game.score.should == 0 + end + + it "should calculate an all ones game" do + roll_many(20, 1) + @game.score.should == 20 + end + + it "should calculate a spare" do + roll_spare + @game.roll(3) + roll_many(17, 0) + @game.score.should == 16 + end + + it "should calculate a strike" do + roll_strike + @game.roll(3) + @game.roll(4) + roll_many(16,0) + @game.score.should == 24 + end + + it "should calculate a perfect game" do + 12.times { roll_strike } + @game.score.should == 300 + end + + private + + def roll_many(n, pins) + n.times { @game.roll(pins) } + end + + def roll_spare + @game.roll(5) + @game.roll(5) + end + + def roll_strike + @game.roll(10) + end +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..78a9263 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,4 @@ +require 'rubygems' +require 'spec' + +require 'bowling_game' \ No newline at end of file diff --git a/test/test_game.rb b/test/test_game.rb index 03fcdbe..edb2786 100644 --- a/test/test_game.rb +++ b/test/test_game.rb @@ -1,6 +1,7 @@ require 'test_helper' class TestGame < Test::Unit::TestCase + def setup @game = BowlingGame.new end @@ -38,9 +39,7 @@ def test_perfect_game private def roll_many(n, pins) - 1.upto(n) do - @game.roll(pins) - end + n.times { @game.roll(pins) } end def roll_spare diff --git a/test/test_helper.rb b/test/test_helper.rb index 715cbea..a0da6ae 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,4 @@ require 'rubygems' require 'test/unit' -require File.expand_path('../../lib/bowling_game', __FILE__) \ No newline at end of file +require 'bowling_game' \ No newline at end of file