1 $:.unshift File.join(File.dirname(__FILE__), "..")
4 require 'shogi_server/player'
5 require 'shogi_server/pairing'
6 require 'test/mock_log_message'
10 unless a.size == 2 && b.size == 2
14 return true if [a.first, a.last] == b || [a.last, a.first] == b
17 class TestPairing < Test::Unit::TestCase
19 @pairing= ShogiServer::Pairing.new
21 def @pairing.start_game(p1,p2)
24 @a = ShogiServer::BasicPlayer.new
29 @a.last_game_win = false
30 @b = ShogiServer::BasicPlayer.new
35 @b.last_game_win = true
36 @c = ShogiServer::BasicPlayer.new
41 @c.last_game_win = true
42 @d = ShogiServer::BasicPlayer.new
47 @d.last_game_win = true
50 def test_include_newbie
51 assert(@pairing.include_newbie?([@a]))
52 assert(!@pairing.include_newbie?([@b]))
53 assert(@pairing.include_newbie?([@b,@a]))
54 assert(!@pairing.include_newbie?([@b,@c]))
58 class TestStartGame < Test::Unit::TestCase
60 @pairing= ShogiServer::StartGame.new
62 def @pairing.start_game(p1,p2)
65 @a = ShogiServer::BasicPlayer.new
70 @b = ShogiServer::BasicPlayer.new
75 @c = ShogiServer::BasicPlayer.new
80 @d = ShogiServer::BasicPlayer.new
87 def test_match_two_players
89 @pairing.match(players)
90 assert_equal(1, $called)
93 def test_match_one_player
95 @pairing.match(players)
96 assert_equal(0, $called)
99 def test_match_zero_player
101 @pairing.match(players)
102 assert_equal(0, $called)
105 def test_match_three_players
107 @pairing.match(players)
108 assert_equal(1, $called)
111 def test_match_four_players
112 players = [@a,@b,@c,@d]
113 @pairing.match(players)
114 assert_equal(2, $called)
118 class TestStartGameWithoutHumans < Test::Unit::TestCase
120 @pairing= ShogiServer::StartGameWithoutHumans.new
123 def @pairing.start_game(p1,p2)
127 @a = ShogiServer::BasicPlayer.new
132 @b = ShogiServer::BasicPlayer.new
137 @c = ShogiServer::BasicPlayer.new
142 @d = ShogiServer::BasicPlayer.new
149 def test_match_one_player
151 @pairing.match(players)
152 assert_equal(0, $called)
155 def test_match_one_player_human
158 @pairing.match(players)
159 assert_equal(0, $called)
162 def test_match_two_players
164 @pairing.match(players)
165 assert_equal(1, $called)
168 def test_match_two_players_humans
172 @pairing.match(players)
173 assert_equal(1, $called)
176 def test_match_zero_player
178 @pairing.match(players)
179 assert_equal(0, $called)
182 def test_match_three_players
184 @pairing.match(players)
185 assert_equal(1, $called)
188 def test_match_three_players_a_human
191 @pairing.match(players)
192 assert_equal(1, $called)
193 assert_equal(1, players.size)
194 assert_equal(@c, players[0])
197 def test_match_three_players_b_human
200 @pairing.match(players)
201 assert_equal(1, $called)
202 assert_equal(1, players.size)
203 assert_equal(@c, players[0])
206 def test_match_three_players_c_human
209 @pairing.match(players)
210 assert_equal(1, $called)
211 assert_equal(1, players.size)
212 assert_equal(@c, players[0])
215 def test_match_three_players_ab_human
219 @pairing.match(players)
220 assert_equal(1, $called)
221 assert_equal(1, players.size)
222 assert_equal(@b, players[0])
225 def test_match_three_players_bc_human
229 @pairing.match(players)
230 assert_equal(1, $called)
231 assert_equal(1, players.size)
232 assert_equal(@c, players[0])
235 def test_match_four_players
236 players = [@a,@b,@c,@d]
237 @pairing.match(players)
238 assert_equal(2, $called)
241 def test_match_four_players_ab_human
244 players = [@a,@b,@c,@d]
245 @pairing.match(players)
246 assert_equal(2, $paired.size)
247 assert(same_pair?([@a,@c], $paired[0]))
248 assert(same_pair?([@b,@d], $paired[1]))
251 def test_match_four_players_bc_human
254 players = [@a,@b,@c,@d]
255 @pairing.match(players)
256 assert_equal(2, $paired.size)
257 assert(same_pair?([@a,@b], $paired[0]))
258 assert(same_pair?([@c,@d], $paired[1]))
261 def test_match_four_players_abc_human
265 players = [@a,@b,@c,@d]
266 @pairing.match(players)
267 assert_equal(2, $paired.size)
268 assert(same_pair?([@a,@d], $paired[0]))
269 assert(same_pair?([@b,@c], $paired[1]))
272 def test_match_four_players_bcd_human
276 players = [@a,@b,@c,@d]
277 @pairing.match(players)
278 assert_equal(2, $paired.size)
279 assert(same_pair?([@a,@b], $paired[0]))
280 assert(same_pair?([@c,@d], $paired[1]))
283 def test_match_four_players_abcd_human
288 players = [@a,@b,@c,@d]
289 @pairing.match(players)
290 assert_equal(2, $paired.size)
291 assert(same_pair?([@a,@b], $paired[0]))
292 assert(same_pair?([@c,@d], $paired[1]))