Skip to content

Instantly share code, notes, and snippets.

@danreedy
Created December 10, 2010 04:53
Show Gist options
  • Save danreedy/735804 to your computer and use it in GitHub Desktop.
Save danreedy/735804 to your computer and use it in GitHub Desktop.
Rather than a simple one-liner, I figured I'd take the time to develop a test case and a full set of classes.
require 'open-uri'
require 'test/unit'
class Spin
def self.winning_number
URI.parse('http://roulette.engineyard.com').read.gsub(/[^\d]/,'').to_i
end
end
class StraightBet
attr_accessor :winning_number
def initialize(number,bid)
@number = number
@bid = bid
end
def payout
if @number == @winning_number
@bid * 35
else
0
end
end
end
bid = StraightBet.new(13,100_00)
bid.winning_number = Spin.winning_number
puts "Your payout: #{bid.payout}"
class Lucky13Test < Test::Unit::TestCase
def setup
@bid = StraightBet.new(13,100_00)
end
def test_the_ball_falls_on_lucky_13
@bid.winning_number = 13
assert_equal(3500_00, @bid.payout)
end
def test_the_ball_does_not_fall_on_luck_13
@bid.winning_number = 15
assert_equal(0_00, @bid.payout)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment