X-Git-Url: http://git.sourceforge.jp/view?p=shogi-server%2Fshogi-server.git;a=blobdiff_plain;f=test%2FTC_floodgate.rb;h=c169b2670549ff4fa6ca9529f56b47d048bc54f9;hp=3dc9cdfec9dc4037a6c4048548fef033efb32d44;hb=ce94a8dae6ddceb9b3af0b43d56da3d11062335e;hpb=68d01a10628408cda4f7345d6ef62ac8067b66f9 diff --git a/test/TC_floodgate.rb b/test/TC_floodgate.rb index 3dc9cdf..c169b26 100644 --- a/test/TC_floodgate.rb +++ b/test/TC_floodgate.rb @@ -8,6 +8,15 @@ require 'test/mock_log_message' $topdir = File.expand_path File.dirname(__FILE__) +class SimplePlayer < ShogiServer::BasicPlayer + attr_accessor :status + def initialize + super + @status = "game_waiting" + @game_name = "floodgate-900-0" + end +end + class TestFloodgate < Test::Unit::TestCase def setup @fg = ShogiServer::League::Floodgate.new(nil) @@ -24,14 +33,45 @@ class TestFloodgate < Test::Unit::TestCase end def test_instance_game_name - fg = ShogiServer::League::Floodgate.new(nil, "floodgate-900-0") - assert(fg.game_name?("floodgate-900-0")) - assert(!fg.game_name?("floodgate-3600-0")) - fg = ShogiServer::League::Floodgate.new(nil, "floodgate-3600-0") + fg = ShogiServer::League::Floodgate.new(nil, {:game_name => "floodgate-900-0"}) assert(fg.game_name?("floodgate-900-0")) assert(!fg.game_name?("floodgate-3600-0")) + fg = ShogiServer::League::Floodgate.new(nil, {:game_name => "floodgate-3600-0"}) + assert(!fg.game_name?("floodgate-900-0")) + assert(fg.game_name?("floodgate-3600-0")) + end + + def test_select_players + league = ShogiServer::League.new(File.dirname(__FILE__)) + league.event = "test" + league.setup_players_database + + a = SimplePlayer.new + a.win = 1 + a.loss = 2 + a.rate = 0 + a.name = "a" + a.player_id = "a+123" + b = SimplePlayer.new + b.win = 10 + b.loss = 20 + b.rate = 1500 + b.name = "b" + b.player_id = "b+456" + c = SimplePlayer.new + c.win = 100 + c.loss = 200 + c.rate = 1000 + c.name = "c" + + league.add a + league.add b + league.add c + + fg = ShogiServer::League::Floodgate.new(league, {:game_name => "floodgate-900-0"}) + + assert_equal([a,b], fg.select_players) end - end class TestDeleteMostPlayingPlayer < Test::Unit::TestCase @@ -88,7 +128,8 @@ class TestMakeEven < Test::Unit::TestCase def test_match_odd players = [@a, @b, @c] @pairing.match(players) - assert_equal([@a, @b], players) + assert_equal(2, players.size) + assert(players[0] != players[1]) end end @@ -137,7 +178,10 @@ class TestRandomize < Test::Unit::TestCase def test_match players = [@a, @b, @c] @pairing.match(players) - assert_equal([@b,@a,@c], players) + assert_equal(3, players.size) + assert(players.include? @a) + assert(players.include? @b) + assert(players.include? @c) end end @@ -395,6 +439,22 @@ class TestFloodgateHistory < Test::Unit::TestCase assert !@history.last_win?("foo") assert !@history.last_lose?("hoge") assert @history.last_lose?("foo") + + assert_equal("foo", @history.last_opponent("hoge")) + assert_equal("hoge", @history.last_opponent("foo")) + + games = @history.win_games("hoge") + assert_equal(1, games.size ) + assert_equal("wdoor+floodgate-900-0-hoge-foo-2", games[0][:game_id]) + games = @history.win_games("foo") + assert_equal(1, games.size ) + assert_equal("wdoor+floodgate-900-0-hoge-foo-1", games[0][:game_id]) + games = @history.loss_games("hoge") + assert_equal(1, games.size ) + assert_equal("wdoor+floodgate-900-0-hoge-foo-1", games[0][:game_id]) + games = @history.loss_games("foo") + assert_equal(1, games.size ) + assert_equal("wdoor+floodgate-900-0-hoge-foo-2", games[0][:game_id]) end end