assert_instance_of(ShogiServer::MonitorOffCommand, cmd)
end
+ def test_monitor2off_command
+ cmd = ShogiServer::Command.factory("%%MONITOR2OFF game_id", @p)
+ assert_instance_of(ShogiServer::Monitor2OffCommand, cmd)
+ end
+
def test_help_command
cmd = ShogiServer::Command.factory("%%HELP", @p)
assert_instance_of(ShogiServer::HelpCommand, cmd)
#
#
+class TestMonitor2OffCommand < Test::Unit::TestCase
+ def setup
+ @p = MockPlayer.new
+ @game = MockGame.new
+ @p.game = @game
+ end
+
+ def test_call
+ cmd = ShogiServer::Monitor2OffCommand.new("%%MONITOR2OFF hoge", @p, nil)
+ rc = cmd.call
+
+ assert_equal(:continue, rc)
+ end
+end
+
+#
+#
class TestHelpCommand < Test::Unit::TestCase
def setup
@p = MockPlayer.new
#
#
class TestMonitorHandler < Test::Unit::TestCase
- def test_not_equal
+ def test_not_equal_players
@player1 = MockPlayer.new
@handler1 = ShogiServer::MonitorHandler1.new @player1
@player2 = MockPlayer.new
def test_header
assert_equal("MONITOR", @handler.header)
end
+
+ def test_equal
+ assert_equal @handler, @handler
+ assert_not_equal @handler, nil
+ end
+
+ def test_not_equal
+ assert_not_equal(@handler, ShogiServer::MonitorHandler2.new(@player))
+ end
def test_write_safe
@handler.write_safe("game_id", "hoge")
assert_equal("MONITOR2", @handler.header)
end
+ def test_equal
+ assert_equal @handler, @handler
+ assert_not_equal @handler, nil
+ end
+
+ def test_not_equal
+ assert_not_equal(@handler, ShogiServer::MonitorHandler1.new(@player))
+ end
+
def test_write_safe
@handler.write_safe("game_id", "hoge")
assert_equal("##[MONITOR2][game_id] hoge\n##[MONITOR2][game_id] +OK\n",
T1
EOF
end
+
+ def test_monitor_add
+ game_name = "hoge-1500-0"
+ board = ShogiServer::Board.new
+ board.initial
+ p1 = MockPlayer.new
+ p1.sente = true
+ p1.name = "p1"
+ p2 = MockPlayer.new
+ p2.sente = false
+ p2.name = "p2"
+
+ game = ShogiServer::Game.new game_name, p1, p2, board
+ handler1 = ShogiServer::MonitorHandler1.new p1
+ handler2 = ShogiServer::MonitorHandler2.new p2
+
+ assert_equal(0, game.monitors.size)
+ game.monitoron(handler1)
+ assert_equal(1, game.monitors.size)
+ game.monitoron(handler2)
+ assert_equal(2, game.monitors.size)
+ game.monitoroff(handler1)
+ assert_equal(1, game.monitors.size)
+ assert_equal(handler2, game.monitors.last)
+ game.monitoroff(handler2)
+ assert_equal(0, game.monitors.size)
+ end
end