Skip to content

Instantly share code, notes, and snippets.

@jeantil
Created February 24, 2011 18:11
Show Gist options
  • Select an option

  • Save jeantil/842583 to your computer and use it in GitHub Desktop.

Select an option

Save jeantil/842583 to your computer and use it in GitHub Desktop.
softeam dojo 4
# To change this template, choose Tools | Templates
# and open the template in the editor.
class Arbitre
def initialize
end
def reponse(secret, guess)
c=0
secret.each_with_index do |e, i|
if(e==guess[i])
c+=1
end
end
m=0
guess.each_with_index do |e,i|
if(e==:mauve)
m+=1
end
end
[c,m]
end
end
# To change this template, choose Tools | Templates
# and open the template in the editor.
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
require 'shoulda'
require 'mastermind'
class TestMastermind < Test::Unit::TestCase
def setup
@arbitre=Arbitre.new
end
should "return 0,0 when all are misplaced and there is only one guess to make" do
assert_equal([0,0], @arbitre.reponse([:bleu],[:blanc]))
end
should "return 1,0 when there is one well placed guess for a secret of 1" do
assert_equal([1,0], @arbitre.reponse([:bleu],[:bleu]))
end
should "return 2,0 when there is two well placed for a secret of 2" do
assert_equal([2,0], @arbitre.reponse([:bleu,:bleu],[:bleu,:bleu]))
end
should "return 3,0 when there is two well placed for a secret of 2" do
assert_equal([3,0], @arbitre.reponse([:bleu,:bleu,:bleu],[:bleu,:bleu,:bleu]))
end
should "return 1,0 when the first is the only well placed for a secret of 2" do
assert_equal([1,0], @arbitre.reponse([:bleu,:bleu],[:bleu,:rouge]))
end
should "return 1,0 when the second is the only well placed for a secret of 2" do
assert_equal([1,0], @arbitre.reponse([:bleu,:bleu],[:rouge,:bleu]))
end
should "return 0,1 when the second is the only misplaced for a secret of 2" do
assert_equal([0,1], @arbitre.reponse([:mauve,:rouge],[:bleu,:mauve]))
end
should "return 0,1 when the third is the only misplaced for a secret of 3" do
assert_equal([0,1], @arbitre.reponse([:rouge,:mauve,:rouge],[:bleu,:bleu,:mauve]))
end
# should "return 0,2 when both guesses are misplaced for a secret of 2" do
# assert_equal([0,1], @arbitre.reponse([:mauve,:rouge],[:rouge,:mauve]))
# end
# should "return 4 well placed when the user guessed the secret" do
# arbitre = Arbitre.new
# assert_equal [4,0], arbitre.eval([:bleu,:rouge,:blanc,:noir], ([:bleu,:rouge,:blanc,:noir])
# end
# should "return 2 well placed and 1 misplaced when the user failed to guess one and misplaced one of the secret" do
# arbitre = Arbitre.new
# assert_equal [2,1], arbitre.eval([:bleu,:rouge,:blanc,:noir], ([:bleu,:rouge,:rose,:blanc])
# end
# should "return 0 well placed and 0 misplaced when the user failed to guess the secret" do
# arbitre = Arbitre.new
# assert_equal [0,0], arbitre.eval([:bleu,:rouge,:blanc,:noir], ([:rose,:mauve,:rose,:jaune])
# end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment