extends TestCase func test_one_tick_lasts_a_twentieth_of_a_second() -> void: var clock := TickClock.new(20) check_eq(clock.advance(0.05), 1, "a full tick") check_eq(clock.advance(0.025), 0, "half a tick") check_eq(clock.advance(0.025), 1, "the second half completes the tick") func test_a_second_of_short_frames_runs_about_twenty_ticks() -> void: var clock := TickClock.new(20) var ticks := 0 for frame in 60: ticks += clock.advance(1.0 / 60.0) # Rounding in floating point may leave the last tick for the next frame. check(ticks == 19 or ticks == 20, "19 or 20 ticks, got %d" % ticks) func test_a_long_stall_runs_at_most_five_ticks_and_forgets_the_rest() -> void: var clock := TickClock.new(20) check_eq(clock.advance(10.0), TickClock.MAX_TICKS_PER_FRAME, "capped") check_eq(clock.advance(0.0), 0, "the rest of the stall is dropped") func test_a_paused_clock_runs_no_ticks() -> void: var clock := TickClock.new(20) clock.paused = true check_eq(clock.advance(1.0), 0, "paused") clock.paused = false check_eq(clock.advance(0.05), 1, "running again")