OSDN Git Service

Merge branch '201312-fix-sacrifice'
[shogi-server/shogi-server.git] / test / TC_floodgate.rb
index 31a2b17..56e242e 100644 (file)
@@ -4,37 +4,10 @@ require 'shogi_server'
 require 'shogi_server/player'
 require 'shogi_server/pairing'
 require 'shogi_server/league/floodgate'
+require 'test/mock_log_message'
 
 $topdir = File.expand_path File.dirname(__FILE__)
 
-class MockLogger
-  def debug(str)
-    #puts str
-  end
-  def info(str)
-    #puts str
-  end
-  def warn(str)
-    puts str
-  end
-  def error(str)
-    puts str
-  end
-end
-
-$logger = MockLogger.new
-def log_message(msg)
-  $logger.info(msg)
-end
-
-def log_warning(msg)
-  $logger.warn(msg)
-end
-
-def log_error(msg)
-  $logger.error(msg)
-end
-
 class TestFloodgate < Test::Unit::TestCase
   def setup
     @fg = ShogiServer::League::Floodgate.new(nil)
@@ -50,6 +23,15 @@ class TestFloodgate < Test::Unit::TestCase
     assert(!ShogiServer::League::Floodgate.game_name?("floodgat-900-0"))
   end
 
+  def test_instance_game_name
+    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
+
 end
 
 class TestDeleteMostPlayingPlayer < Test::Unit::TestCase
@@ -106,7 +88,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
 
@@ -155,7 +138,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
 
@@ -413,6 +399,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