1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
11 class TestClock < Test::Unit::TestCase
31 clock = Clock.new(2, 0, nil, FakeTimer)
32 clock.observe(:timer) {|timer|}
33 clock.observe(:elapsed) { elapsed = true }
40 8.times { clock.tick }
46 assert_equal({ :main => 1 }, timer)
49 9.times { clock.tick }
62 # 10 seconds main time, 1 second increment
63 clock = Clock.new(10, 1, nil, FakeTimer)
64 clock.observe(:timer) {|timer|}
65 clock.observe(:elapsed) { elapsed = true }
68 80.times { clock.tick }
70 assert_equal({:main => 2}, timer)
75 assert_equal({:main => 3}, timer)
78 15.times { clock.tick }
80 assert_equal({:main => 2}, timer)
83 14.times { clock.tick }
85 assert_equal({:main => 1}, timer)
97 # 10 seconds main time, 1 second byoyomi, 2 periods
98 clock = Clock.new(10, 0, Clock::ByoYomi.new(1, 2), FakeTimer)
99 clock.observe(:timer) {|timer|}
100 clock.observe(:elapsed) { elapsed = true }
103 80.times { clock.tick }
105 assert_equal({:main => 2}, timer)
107 25.times { clock.tick }
109 assert_equal({:byoyomi => Clock::ByoYomi.new(1, 2)}, timer)
111 10.times { clock.tick }
113 assert_equal({:byoyomi => Clock::ByoYomi.new(1, 1) }, timer)
115 5.times { clock.tick }