1 $:.unshift File.join(File.dirname(__FILE__), "..")
18 $logger = MockLogger.new
20 class TestFloodgate < Test::Unit::TestCase
22 @fg = ShogiServer::League::Floodgate.new(nil)
30 assert(ShogiServer::League::Floodgate.game_name?("floodgate-900-0"))
31 assert(ShogiServer::League::Floodgate.game_name?("floodgate-0-10"))
32 assert(!ShogiServer::League::Floodgate.game_name?("floodgat-900-0"))
37 class TestPairing < Test::Unit::TestCase
39 @pairing= ShogiServer::Pairing.new
40 @a = ShogiServer::BasicPlayer.new
44 @b = ShogiServer::BasicPlayer.new
48 @c = ShogiServer::BasicPlayer.new
54 def test_delete_most_playing_player
55 players = [@a, @b, @c]
56 @pairing.delete_most_playing_player(players)
57 assert_equal([@a,@b], players)
60 def test_delete_least_rate_player
61 players = [@a, @b, @c]
62 @pairing.delete_least_rate_player(players)
63 assert_equal([@b,@c], players)
67 class TestRandomPairing < Test::Unit::TestCase
69 @pairing= ShogiServer::RandomPairing.new
71 def @pairing.start_game(p1,p2)
74 @a = ShogiServer::BasicPlayer.new
77 @b = ShogiServer::BasicPlayer.new
80 @c = ShogiServer::BasicPlayer.new
85 def test_random_match_1
87 @pairing.match(players)
88 assert_equal(0, $called)
91 def test_random_match_2
93 @pairing.match(players)
94 assert_equal(1, $called)
97 def test_random_match_3
98 players = [@a, @b, @c]
99 @pairing.match(players)
100 assert_equal(1, $called)
104 class TestSwissPairing < Test::Unit::TestCase
106 @pairing= ShogiServer::SwissPairing.new
108 def @pairing.start_game(p1,p2)
111 @a = ShogiServer::BasicPlayer.new
116 @a.last_game_win = false
117 @b = ShogiServer::BasicPlayer.new
122 @b.last_game_win = true
123 @c = ShogiServer::BasicPlayer.new
128 @c.last_game_win = true
129 @d = ShogiServer::BasicPlayer.new
134 @d.last_game_win = true
138 return players.sort{|a,b| a.name <=> b.name}
141 def test_include_newbie
142 assert(@pairing.include_newbie?([@a]))
143 assert(!@pairing.include_newbie?([@b]))
144 assert(@pairing.include_newbie?([@b,@a]))
145 assert(!@pairing.include_newbie?([@b,@c]))
150 assert_equal(0, $pairs.size)
155 assert_equal(0, $pairs.size)
159 @pairing.match([@a,@b])
160 assert_equal(1, $pairs.size)
161 assert_equal(sort([@a,@b]), sort($pairs.first))
165 @pairing.match([@c,@b])
166 assert_equal(1, $pairs.size)
167 assert_equal(sort([@b,@c]), sort($pairs.first))
171 @pairing.match([@c,@b,@a])
172 assert_equal(1, $pairs.size)
173 assert_equal(sort([@b,@c]), sort($pairs.first))
177 @pairing.match([@c,@b,@a,@d])
178 assert_equal(2, $pairs.size)
179 assert_equal(sort([@b,@d]), sort($pairs.first))
180 assert_equal(sort([@a,@c]), sort($pairs.last))
184 class TestExcludeSacrifice < Test::Unit::TestCase
194 @obj = ShogiServer::ExcludeSacrifice.new(@dummy)
195 @a = ShogiServer::BasicPlayer.new
201 @a.last_game_win = false
202 @b = ShogiServer::BasicPlayer.new
203 @b.player_id = "gps500+e293220e3f8a3e59f79f6b0efffaa931"
208 @b.last_game_win = true
209 @c = ShogiServer::BasicPlayer.new
215 @c.last_game_win = true
220 assert_equal(1, @dummy.players.size)
225 assert_equal(0, @dummy.players.size)
230 assert_equal(2, @dummy.players.size)
234 @obj.match([@a, @b, @c])
235 assert_equal(2, @dummy.players.size)
240 assert_equal(2, @dummy.players.size)