OSDN Git Service

* [shogi-server]
[shogi-server/shogi-server.git] / test / TC_pairing.rb
index 660e2dd..d9871e3 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
@@ -570,3 +571,58 @@ class TestLeastDiff < Test::Unit::TestCase
   end
 end
 
+class TestExcludeUnratedPlayers < Test::Unit::TestCase
+  def setup
+    @pairing= ShogiServer::ExcludeUnratedPlayers.new
+    @a = ShogiServer::BasicPlayer.new
+    @a.name = "a"
+    @a.win  = 1
+    @a.loss = 2
+    @a.rate = 0
+    @b = ShogiServer::BasicPlayer.new
+    @b.name = "b"
+    @b.win  = 10
+    @b.loss = 20
+    @b.rate = 1500
+    @c = ShogiServer::BasicPlayer.new
+    @c.name = "c"
+    @c.win  = 100
+    @c.loss = 200
+    @c.rate = 1000
+    @d = ShogiServer::BasicPlayer.new
+    @d.name = "d"
+    @d.win  = 1000
+    @d.loss = 2000
+    @d.rate = 2000
+  end
+
+  def test_match_without_any_players
+    players = []
+    @pairing.match(players)
+    assert_equal([], players)
+  end
+
+  def test_match_without_unrated_player_1
+    players = [@b, @c, @d]
+    @pairing.match(players)
+    assert_equal([@b, @c, @d], players)
+  end
+
+  def test_match_without_unrated_player_2
+    players = [@b]
+    @pairing.match(players)
+    assert_equal([@b], players)
+  end
+
+  def test_match_with_unrated_player_1
+    players = [@a, @b, @c, @d]
+    @pairing.match(players)
+    assert_equal([@b, @c, @d], players)
+  end
+
+  def test_match_with_unrated_player_2
+    players = [@a]
+    @pairing.match(players)
+    assert_equal([], players)
+  end
+end