Created
November 8, 2017 20:21
-
-
Save rickhull/e1eadca86fc72ea40e1f818578b92abf 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 'minitest/autorun' | |
def rock(other) | |
case other | |
when :rock then 0 | |
when :paper then :paper | |
when :scissors then :rock | |
else | |
raise "unknown value: #{other}" | |
end | |
end | |
def paper(other) | |
case other | |
when :rock then :paper | |
when :paper then 0 | |
when :scissors then :scissors | |
else | |
raise "unknown value: #{other}" | |
end | |
end | |
def scissors(other) | |
case other | |
when :rock then :rock | |
when :paper then :scissors | |
when :scissors then 0 | |
else | |
raise "unknown value: #{other}" | |
end | |
end | |
def winner(left, right) | |
send(left, right) | |
end | |
describe "winner" do | |
it "must" do | |
winner(:rock, :rock).must_equal 0 | |
winner(:rock, :paper).must_equal :paper | |
winner(:rock, :scissors).must_equal :rock | |
winner(:paper, :rock).must_equal :paper | |
winner(:paper, :paper).must_equal 0 | |
winner(:paper, :scissors).must_equal :scissors | |
winner(:scissors, :rock).must_equal :rock | |
winner(:scissors, :paper).must_equal :scissors | |
winner(:scissors, :scissors).must_equal 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment