Created
January 15, 2010 17:45
-
-
Save davelyon/278254 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
require 'test/unit' | |
class Piece | |
def self.beats(type) | |
self.instance_eval do | |
define_method "beats_#{type}?".intern do | |
true | |
end | |
end | |
end | |
def method_missing(type) | |
false | |
end | |
end | |
class Rock < Piece | |
beats :scissors | |
end | |
class Paper < Piece | |
beats :rock | |
end | |
class Scissors < Piece | |
beats :paper | |
end | |
# TEST METHODS | |
class RPS_Test < Test::Unit::TestCase | |
def setup | |
@rock = Rock.new() | |
@scissors = Scissors.new() | |
@paper = Paper.new() | |
end | |
def test_rock_should_beat_scissors | |
assert(@rock.beats_scissors?, "Rock should beat scissors.") | |
end | |
def test_scissors_should_beat_paper | |
assert(@scissors.beats_paper?, "Scissors should beat paper.") | |
end | |
def test_paper_should_beat_rock | |
assert(@paper.beats_rock?, "Paper should beat rock.") | |
end | |
def test_scissors_should_lose_to_rock | |
assert([email protected]_rock?, "Scissors cannot beat rock.") | |
end | |
def test_rock_should_lose_to_paper | |
assert([email protected]_paper?, "Rock cannot beat paper.") | |
end | |
def test_paper_should_lose_to_scissors | |
assert([email protected]_scissors?, "Paper cannot beat scissors.") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment