Created
April 24, 2013 04:30
-
-
Save amirci/5449626 to your computer and use it in GitHub Desktop.
Acceptance tests for bowling game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'bowling' | |
describe Line do | |
def roll_balls(line, frames) | |
frames.each { |pins| line.knock pins } | |
end | |
def self.should_behave_like_a_bowling_game(result, frames, descr=nil) | |
context descr || "when doing a game with #{frames}" do | |
before { roll_balls subject, frames} | |
its(:score) { should == result } | |
end | |
end | |
describe 'border scenarios' do | |
should_behave_like_a_bowling_game 0, [0] * 20, 'gutter' | |
should_behave_like_a_bowling_game 300, [10] * 12, 'awesome sauce' | |
end | |
describe 'lame games' do | |
should_behave_like_a_bowling_game 20, [1] * 20, 'only ones' | |
should_behave_like_a_bowling_game 20, [2, 8, 5] + [0] * 17, 'only one spare' | |
should_behave_like_a_bowling_game 26, [10, 3, 5] + [0] * 17, 'only one strike' | |
end | |
describe 'lots of spares' do | |
should_behave_like_a_bowling_game 150, [5] * 20 << 5, '10 pairs of 5 + bonus roll 5' | |
should_behave_like_a_bowling_game 195, [10, 5, 5] * 5 << 5, 'strike and pair of 5' | |
end | |
nine_empty_frames = [0] * 18 | |
describe 'spare on the 10th frame' do | |
should_behave_like_a_bowling_game 12, nine_empty_frames + [2, 8, 2] , "not a strike" | |
should_behave_like_a_bowling_game 20, nine_empty_frames + [2, 8, 10] , "bonus roll strike" | |
end | |
describe 'strike on the 10th frame' do | |
should_behave_like_a_bowling_game 30, nine_empty_frames + [10, 10, 10], "two bonus roll strikes" | |
should_behave_like_a_bowling_game 20, nine_empty_frames + [10, 2, 8] , "two bonus rolls and a spare" | |
end | |
describe "playing average games" do | |
should_behave_like_a_bowling_game 131, [9, 0, 3, 7, 6, 1, 3, 7, 8, 1, 5, 5, 0, 10, 8, 0, 7, 3, 8, 2, 8] | |
should_behave_like_a_bowling_game 82, [9, 0, 3, 5, 6, 1, 3, 6, 8, 1, 5, 3, 2, 5, 8, 0, 7, 1, 8, 1] | |
should_behave_like_a_bowling_game 193, [10, 3, 7, 6, 1, 10, 10, 10, 2, 8, 9, 0, 7, 3, 10, 10, 10] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment