Skip to content

Instantly share code, notes, and snippets.

@raphaelmolesim
Created June 24, 2010 18:25
Show Gist options
  • Save raphaelmolesim/451768 to your computer and use it in GitHub Desktop.
Save raphaelmolesim/451768 to your computer and use it in GitHub Desktop.
class StonePaperScissor
@@rules = Hash.new(:draw).merge({
[:stone, :scissor] => :left_wins,
[:stone, :paper] => :right_wins,
[:paper, :scissor] => :right_wins,
[:paper, :stone] => :left_wins,
[:scissor, :stone] => :right_wins,
[:scissor, :paper] => :left_wins,
})
def play(player_one, player_two)
@@rules[ [player_one, player_two] ]
end
end
require 'stone_paper_scissor'
describe "StonePaperScissor" do
before do
@game = StonePaperScissor.new
end
it "should be able to create a instance" do
@game.should be_a StonePaperScissor
end
it "should say that stone beats scissor" do
@game.play(:stone, :scissor).should be == :left_wins
end
it "should say that scissor beats paper" do
@game.play(:scissor, :paper).should be == :left_wins
end
it "should say that paper beats stone" do
@game.play(:paper, :stone).should be == :left_wins
end
it "paper should fail for scissor" do
@game.play(:paper, :scissor).should be == :right_wins
end
it "scissor should fail for stone" do
@game.play(:scissor, :stone).should be == :right_wins
end
it "should score draw" do
@game.play(:scissor, :scissor).should be == :draw
end
it "consecutive games are always the same" do
@game.play(:scissor, :scissor).should be == :draw
@game.play(:scissor, :scissor).should be == :draw
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment