/* * Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/piot/time-tick * Licensed under the MIT License. See LICENSE in the project root for license information. */ use monotonic_time_rs::{Millis, MillisDuration}; use time_tick::TimeTick; #[test] fn time_tick() { let mut now = Millis::new(0); let mut timer = TimeTick::new(now, MillisDuration::from_millis(10), 100); now += MillisDuration::from_millis(20); assert_eq!(timer.calculate_ticks(now), 2); timer.performed_ticks(2); now += MillisDuration::from_millis(9); assert_eq!(timer.calculate_ticks(now), 0); } #[test] fn time_tick_change_duration() { let mut now = Millis::new(0); let mut timer = TimeTick::new(now, MillisDuration::from_millis(10), 100); now += MillisDuration::from_millis(20); assert_eq!(timer.calculate_ticks(now), 2); timer.performed_ticks(2); now += MillisDuration::from_millis(9); timer.set_tick_duration(MillisDuration::from_millis(9)); assert_eq!(timer.calculate_ticks(now), 1); timer.performed_ticks(1); now += MillisDuration::from_millis(8); assert_eq!(timer.calculate_ticks(now), 0); }