Skip to content

Commit

Permalink
Adding tests using Rspec, and pdf file with Kata presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva committed May 1, 2010
1 parent 1b15db7 commit 23b9ee0
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
Binary file added files/Bowling Game Kata.pdf
Binary file not shown.
53 changes: 53 additions & 0 deletions 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
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,4 @@
require 'rubygems'
require 'spec'

require 'bowling_game'
5 changes: 2 additions & 3 deletions test/test_game.rb
@@ -1,6 +1,7 @@
require 'test_helper'

class TestGame < Test::Unit::TestCase

def setup
@game = BowlingGame.new
end
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
@@ -1,4 +1,4 @@
require 'rubygems'
require 'test/unit'

require File.expand_path('../../lib/bowling_game', __FILE__)
require 'bowling_game'

0 comments on commit 23b9ee0

Please sign in to comment.