Last active
August 29, 2015 14:02
-
-
Save shortdiv/02f984b706d81d4cf076 to your computer and use it in GitHub Desktop.
Yahtzee Kata
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
class Die | |
def initialize | |
roll | |
end | |
def roll | |
@value = rand(1..6) | |
end | |
def get_value | |
return @value | |
end | |
end | |
class Player | |
def initialize | |
@score = 0 | |
end | |
def get_score | |
@score | |
end | |
end | |
class Game | |
def initialize | |
roll_dice | |
end | |
def roll_dice | |
@dice = Array.new | |
5.times do | |
@dice.push(Die.new) | |
end | |
end | |
def get_dice | |
@dice | |
end | |
def print_dice | |
@dice.each do |x| | |
puts x.get_value | |
end | |
end | |
end | |
#### Rspec Code #### | |
require_relative "die" | |
describe Die do | |
it 'should have one integer value at any given time' do | |
@die = Die.new | |
(@die.get_value).should < 7 | |
(@die.get_value).should > 0 | |
end | |
end | |
describe Player do | |
it 'should have a score' do | |
@player = Player.new | |
@player.get_score.should > -1 | |
end | |
end | |
describe Game do | |
it 'should have 5 die' do | |
@game = Game.new | |
@game.get_dice.length.should == 5 | |
@game.print_dice | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment