Skip to content

Instantly share code, notes, and snippets.

@tos-kamiya
Created August 10, 2012 07:29
Show Gist options
  • Save tos-kamiya/3312284 to your computer and use it in GitHub Desktop.
Save tos-kamiya/3312284 to your computer and use it in GitHub Desktop.
rps-game unittest
require 'test/unit'
require 'rps'
class RPSTestCase < Test::Unit::TestCase
def test_simple_win_lose
# :rock loses :paper
turn_person = rps_game([[:rock], [:paper]])
assert_equal(turn_person, [0, 1])
# :rock wins :scissors
turn_person = rps_game([[:rock], [:scissors]])
assert_equal(turn_person, [0, 0])
# :sissors wins :paper
turn_person = rps_game([[:paper], [:scissors]])
assert_equal(turn_person, [0, 1])
end
def test_missing_hands
# player 1 does not show a hand at 2nd turn, so loses.
data = [[:rock, :paper], [:rock]]
turn, person = rps_game(data)
assert_equal(turn, 1)
assert_equal(person, 0)
end
def test_draw
turn_person = rps_game([[:rock], [:rock]])
assert_equal(turn_person, [-1, -1])
turn_person = rps_game([[:paper], [:paper]])
assert_equal(turn_person, [-1, -1])
turn_person = rps_game([[:scissors], [:scissors]])
assert_equal(turn_person, [-1, -1])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment