Skip to content

Instantly share code, notes, and snippets.

@jdmorlan
Created May 13, 2015 03:51
Show Gist options
  • Save jdmorlan/b7cc8916d24ed50f49ec to your computer and use it in GitHub Desktop.
Save jdmorlan/b7cc8916d24ed50f49ec to your computer and use it in GitHub Desktop.
Rock, Paper, Scissors Algorithm Test
require 'minitest/autorun'
require_relative 'rps_algorithm'
class AlgorithmTest < Minitest::Test
def setup
@algo = RPSAlgorithm.new
end
[*(0..3000)].each do |value|
define_method("test_paper_beats_rock_#{value}") do
paper = value
rock = value + 1
scissors = value + 2
rps_values = {paper: paper, rock: rock, scissors: scissors}
@algo.set_values(rps_values)
assert_equal("paper", @algo.get_winner(:paper, :rock).to_s)
end
define_method("test_rock_beats_scissors_#{value}") do
paper = value
rock = value + 1
scissors = value + 2
rps_values = {paper: paper, rock: rock, scissors: scissors}
@algo.set_values(rps_values)
puts "Paper = #{paper}"
assert_equal("rock", @algo.get_winner(:scissors, :rock).to_s)
end
define_method("test_scissors_beats_paper_#{value}") do
paper = value
rock = value + 1
scissors = value + 2
rps_values = {paper: paper, rock: rock, scissors: scissors}
@algo.set_values(rps_values)
assert_equal("scissors", @algo.get_winner(:scissors, :paper).to_s)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment