OSDN Git Service

Fixed a bug which was found in a long test.
authorDaigo Moriwaki <daigo@debian.org>
Sun, 24 Mar 2013 13:01:51 +0000 (22:01 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Sun, 24 Mar 2013 13:01:51 +0000 (22:01 +0900)
shogi_server/pairing.rb
test/TC_pairing.rb

index bb840fe..8ad9336 100644 (file)
@@ -388,17 +388,6 @@ module ShogiServer
       players.shuffle
     end
 
-    def average_rate(players)
-      n=0
-      sum=0
-      players.find_all{|p| p.rate}.each do |p|
-        n += 1
-        sum += p.rate
-      end
-
-      return n > 0 ? sum/n : 2150 # interger
-    end
-
     # Returns a player's rate value.
     # 1. If it has a valid rate, return the rate.
     # 2. If it has no valid rate, return average of the following values:
@@ -504,9 +493,9 @@ module ShogiServer
           min_score = s
         end
       end
-      log_message("Floodgate: the least score %d (%d per player)" % [min_score, min_score/players.size])
+      log_message("Floodgate: the least score %d (%d per player) [%s]" % [min_score, min_score/players.size, scores.join(" ")])
 
-      players = matches[min_index]
+      players.replace(matches[min_index])
     end
   end
 
index 660e2dd..90cea15 100644 (file)
@@ -475,11 +475,12 @@ class TestLeastDiff < Test::Unit::TestCase
   end
 
   def test_match_three_players
-    players = [@a,@b,@h]
+    players = [@h,@a,@b]
     assert_equal(300,  @pairing.calculate_diff_with_penalty([@a,@b,@h],nil))
     assert_equal(2200, @pairing.calculate_diff_with_penalty([@b,@h,@a],nil))
     r = @pairing.match(players)
     assert_pairs([@a,@b,@h], r)
+    assert_pairs([@a,@b,@h], players)
   end
 
   def test_calculate_diff_with_penalty