Created
May 2, 2013 04:07
-
-
Save teancom/5500095 to your computer and use it in GitHub Desktop.
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
# This one works | |
class DiceSet | |
def roll(size) | |
@dice = [] | |
size.times do |x| | |
@dice[x] = rand(1..6) | |
end | |
end | |
def values | |
@dice | |
end | |
end | |
vs | |
# This one doesn't (i.e., the test fails) - when run from within the koan test | |
# It totally works fine when run in irb | |
class DiceSet | |
def initialize | |
@dice = [] | |
end | |
def roll(size) | |
size.times do |x| | |
@dice[x] = rand(1..6) | |
end | |
end | |
def values | |
@dice | |
end | |
end | |
def test_dice_values_should_change_between_rolls | |
dice = DiceSet.new | |
dice.roll(5) | |
first_time = dice.values | |
dice.roll(5) | |
second_time = dice.values | |
assert_not_equal first_time, second_time, | |
"Two rolls should not be equal" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That makes a ton of sense, Carlo. Thanks!