From 31af9d4ee12067cfd2061b74b577f8028f169fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Fri, 28 Jan 2022 16:17:54 +0000 Subject: [PATCH] fix timer test to be less reliant on float precision (#3789) # Objective - Test is failing on nightly after the merge of https://github.com/rust-lang/rust/pull/90247 - It was relying on the precision of the duration of `1.0 / 3.0` ## Solution - Fix the test to be less reliant on float precision to have the same result --- crates/bevy_core/src/time/timer.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/bevy_core/src/time/timer.rs b/crates/bevy_core/src/time/timer.rs index b9bd0800de38e..fb01966901104 100644 --- a/crates/bevy_core/src/time/timer.rs +++ b/crates/bevy_core/src/time/timer.rs @@ -469,15 +469,18 @@ mod tests { #[test] fn times_finished_precise() { let mut t = Timer::from_seconds(0.01, true); - let duration = Duration::from_secs_f64(1.0 / 3.0); + let duration = Duration::from_secs_f64(0.333); + // total duration: 0.333 => 33 times finished t.tick(duration); assert_eq!(t.times_finished(), 33); + // total duration: 0.666 => 33 times finished t.tick(duration); assert_eq!(t.times_finished(), 33); + // total duration: 0.999 => 33 times finished t.tick(duration); assert_eq!(t.times_finished(), 33); - // It has one additional tick this time to compensate for missing 100th tick + // total duration: 1.332 => 34 times finished t.tick(duration); assert_eq!(t.times_finished(), 34); }