OSDN Git Service

* [shogi-server]
[shogi-server/shogi-server.git] / test / TC_floodgate.rb
index c019a68..31a2b17 100644 (file)
@@ -5,15 +5,20 @@ require 'shogi_server/player'
 require 'shogi_server/pairing'
 require 'shogi_server/league/floodgate'
 
+$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
 
@@ -26,6 +31,10 @@ 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)
@@ -43,47 +52,6 @@ class TestFloodgate < Test::Unit::TestCase
 
 end
 
-class TestPairing < Test::Unit::TestCase  
-  def setup
-    @pairing= ShogiServer::Pairing.new
-    $pairs = []
-    def @pairing.start_game(p1,p2)
-      $pairs << [p1,p2]
-    end
-    @a = ShogiServer::BasicPlayer.new
-    @a.name = "a"
-    @a.win  = 1
-    @a.loss = 2
-    @a.rate = 0
-    @a.last_game_win = false
-    @b = ShogiServer::BasicPlayer.new
-    @b.name = "b"
-    @b.win  = 10
-    @b.loss = 20
-    @b.rate = 1500
-    @b.last_game_win = true
-    @c = ShogiServer::BasicPlayer.new
-    @c.name = "c"
-    @c.win  = 100
-    @c.loss = 200
-    @c.rate = 1000
-    @c.last_game_win = true
-    @d = ShogiServer::BasicPlayer.new
-    @d.name = "d"
-    @d.win  = 1000
-    @d.loss = 2000
-    @d.rate = 1800
-    @d.last_game_win = true
-  end
-
-  def test_include_newbie
-    assert(@pairing.include_newbie?([@a]))
-    assert(!@pairing.include_newbie?([@b]))
-    assert(@pairing.include_newbie?([@b,@a]))
-    assert(!@pairing.include_newbie?([@b,@c]))
-  end
-end
-
 class TestDeleteMostPlayingPlayer < Test::Unit::TestCase
   def setup
     @pairing= ShogiServer::DeleteMostPlayingPlayer.new
@@ -309,50 +277,66 @@ class TestSwissPairing < Test::Unit::TestCase
     @a = ShogiServer::BasicPlayer.new
     @a.player_id = "a"
     @a.rate = 0
+    @a.game_name = "floodgate-900-0"
     @b = ShogiServer::BasicPlayer.new
     @b.player_id = "b"
     @b.rate = 1000
+    @b.game_name = "floodgate-900-0"
     @c = ShogiServer::BasicPlayer.new
     @c.player_id = "c"
     @c.rate = 1500
+    @c.game_name = "floodgate-900-0"
     @d = ShogiServer::BasicPlayer.new
     @d.player_id = "d"
     @d.rate = 2000
+    @d.game_name = "floodgate-900-0"
 
     @players = [@a, @b, @c, @d]
 
-    @file = Pathname.new(File.join(File.dirname(__FILE__), "floodgate_history.yaml"))
-    @history = ShogiServer::League::Floodgate::History.new @file
+    @file = Pathname.new(File.join(File.dirname(__FILE__), "floodgate_history_900_0.yaml"))
+    @history = ShogiServer::League::Floodgate::History.factory @file
 
-    @swiss = ShogiServer::Swiss.new @history
+    @swiss = ShogiServer::Swiss.new
   end
 
   def teardown
     @file.delete if @file.exist?
   end
 
+  def test_none
+    players = []
+    @swiss.match players
+    assert(players.empty?)
+  end
+
   def test_all_win
-    def @history.last_win?(player_id)
-      true
+    ShogiServer::League::Floodgate::History.class_eval do
+      def last_win?(player_id)
+        true
+      end
     end
     @swiss.match @players
     assert_equal([@d, @c, @b, @a], @players)
   end
 
   def test_all_lose
-    def @history.last_win?(player_id)
-      false
+    ShogiServer::League::Floodgate::History.class_eval do
+      def last_win?(player_id)
+        false
+      end
     end
     @swiss.match @players
     assert_equal([@d, @c, @b, @a], @players)
   end
 
   def test_one_win
-    def @history.last_win?(player_id)
-      if player_id == "a"
-        true
-      else
-        false
+    ShogiServer::League::Floodgate::History.class_eval do
+      def last_win?(player_id)
+        if player_id == "a"
+          true
+        else
+          false
+        end
       end
     end
     @swiss.match @players
@@ -360,11 +344,13 @@ class TestSwissPairing < Test::Unit::TestCase
   end
 
   def test_two_win
-    def @history.last_win?(player_id)
-      if player_id == "a" || player_id == "d"
-        true
-      else
-        false
+    ShogiServer::League::Floodgate::History.class_eval do
+      def last_win?(player_id)
+        if player_id == "a" || player_id == "d"
+          true
+        else
+          false
+        end
       end
     end
     @swiss.match @players