OSDN Git Service

Getting an absolute location of this file was wrong if it was a synbolic link. This...
[shogi-server/shogi-server.git] / test / TC_floodgate.rb
index 3a1a471..c169b26 100644 (file)
@@ -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)
@@ -32,6 +41,37 @@ class TestFloodgate < Test::Unit::TestCase
     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