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
30 clock = Clock.new(2000, 0, FakeTimer)
31 clock.on(:timer) {|timer|}
37 8.times { clock.tick }
41 assert_equal(1000, timer)
44 9.times { clock.tick }
48 assert_equal(0, timer)
54 # 10 seconds main time, 1 second increment
55 clock = Clock.new(10000, 1000, FakeTimer)
56 clock.on(:timer) {|timer|}
59 80.times { clock.tick }
60 assert_equal(2000, timer)
64 assert_equal(3000, timer)
67 15.times { clock.tick }
68 assert_equal(2000, timer)
71 14.times { clock.tick }
72 assert_equal(1000, timer)
76 assert_equal(0, timer)
79 7.times { clock.tick }
86 clock = Clock.new(5000, 0, FakeTimer)
87 clock.on(:timer) {|timer|}
88 clock.resolution = 100
91 24.times { clock.tick }
92 assert_equal(2600, timer)
96 assert_equal(2500, timer)
99 30.times { clock.tick }
100 assert_equal(-500, timer)
103 def test_invalid_resolution
104 clock = Clock.new(10, 0, FakeTimer)
105 assert_raise(RuntimeError) do
106 clock.resolution = 50