1 $:.unshift File.join(File.dirname(__FILE__), "..")
3 require 'test/mock_player'
4 require 'shogi_server/board'
5 require 'shogi_server/game'
6 require 'shogi_server/player'
15 class TestTimeClockFactor < Test::Unit::TestCase
17 c = ShogiServer::TimeClock::factory(1, "hoge-900-0")
18 assert_instance_of(ShogiServer::ChessClock, c)
20 c = ShogiServer::TimeClock::factory(1, "hoge-1500-60")
21 assert_instance_of(ShogiServer::ChessClock, c)
24 def test_stop_watch_clock
25 c = ShogiServer::TimeClock::factory(1, "hoge-1500-060")
26 assert_instance_of(ShogiServer::StopWatchClock, c)
30 class TestChessClock < Test::Unit::TestCase
31 def test_time_duration
32 tc = ShogiServer::ChessClock.new(1, 1500, 60)
33 assert_equal(1, tc.time_duration(100.1, 100.9))
34 assert_equal(1, tc.time_duration(100, 101))
35 assert_equal(1, tc.time_duration(100.1, 101.9))
36 assert_equal(2, tc.time_duration(100.1, 102.9))
37 assert_equal(2, tc.time_duration(100, 102))
40 def test_without_byoyomi
41 tc = ShogiServer::ChessClock.new(1, 1500, 0)
43 p = DummyPlayer.new 100
44 assert(!tc.timeout?(p, 100, 101))
45 assert(!tc.timeout?(p, 100, 199))
46 assert(tc.timeout?(p, 100, 200))
47 assert(tc.timeout?(p, 100, 201))
51 tc = ShogiServer::ChessClock.new(1, 1500, 60)
53 p = DummyPlayer.new 100
54 assert(!tc.timeout?(p, 100, 101))
55 assert(!tc.timeout?(p, 100, 259))
56 assert(tc.timeout?(p, 100, 260))
57 assert(tc.timeout?(p, 100, 261))
59 p = DummyPlayer.new 30
60 assert(!tc.timeout?(p, 100, 189))
61 assert(tc.timeout?(p, 100, 190))
64 def test_with_byoyomi2
65 tc = ShogiServer::ChessClock.new(1, 0, 60)
68 assert(!tc.timeout?(p, 100, 159))
69 assert(tc.timeout?(p, 100, 160))
73 class TestStopWatchClock < Test::Unit::TestCase
74 def test_time_duration
75 tc = ShogiServer::StopWatchClock.new(1, 1500, 60)
76 assert_equal(0, tc.time_duration(100.1, 100.9))
77 assert_equal(0, tc.time_duration(100, 101))
78 assert_equal(0, tc.time_duration(100, 159.9))
79 assert_equal(60, tc.time_duration(100, 160))
80 assert_equal(60, tc.time_duration(100, 219))
81 assert_equal(120, tc.time_duration(100, 220))
85 tc = ShogiServer::StopWatchClock.new(1, 600, 60)
87 p = DummyPlayer.new 60
88 assert(!tc.timeout?(p, 100, 159))
89 assert(tc.timeout?(p, 100, 160))