ソースコードを綺麗にブログに書く
require 'test/unit' class Janken def hoi(player) judge(player,gcp) end #戻り値はユーザ側の勝ち負け(1:勝ち、-1:負け、0あいこ) def judge(player,computer) tab = {} #グー tab["gg"] = 0 tab["gc"] = 1 tab["gp"] = -1 #チョキ tab["cg"] = -1 tab["cc"] = 0 tab["cp"] = 1 #パー tab["pg"] = 1 tab["pc"] = -1 tab["pp"] = 0 tab["#{player}#{computer}"] end def gcp ["g","c","p"].sample end end class TestJanken < Test::Unit::TestCase def test_gcp assert_equal "g", Janken.gcp assert_equal "c", Janken.gcp assert_equal "p", Janken.gcp end end