Created
February 21, 2013 19:08
-
-
Save zankich/5007224 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class Game | |
| def initialize() | |
| @score = 0 | |
| @frame = [] | |
| @frame_number = 0 | |
| @first = true | |
| end | |
| def roll(number_of_pins) | |
| if @first | |
| @frame.push(number_of_pins) | |
| # @frame.last += number_of_pins if @frame.last == 10 | |
| @first = false | |
| else | |
| @frame[@frame_number] += number_of_pins | |
| @first = true | |
| @frame_number += 1 | |
| end | |
| end | |
| def score() | |
| @frame.each do |n| | |
| @score += n | |
| end | |
| @score | |
| end | |
| def frame | |
| @frame_number | |
| end | |
| end |
This file contains hidden or 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 './game' | |
| describe Game do | |
| it "should add increment your score" do | |
| g = Game.new | |
| g.roll(10) | |
| g.score.should eq(10) | |
| end | |
| it "should accept two rolls per frame" do | |
| g = Game.new | |
| g.roll(5) | |
| g.roll(2) | |
| g.frame.should eq(1) | |
| end | |
| # it "should calculate a spare" do | |
| # g = Game.new | |
| # g.roll(5) | |
| # g.roll(5) | |
| # g.roll(2) | |
| # g.roll(0) | |
| # g.score.should eq(14) | |
| # end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment