Skip to content

Commit 31af9d4

Browse files
mockersfcart
authored andcommitted
fix timer test to be less reliant on float precision (#3789)
# Objective - Test is failing on nightly after the merge of rust-lang/rust#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
1 parent ef5c8e8 commit 31af9d4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

crates/bevy_core/src/time/timer.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -469,15 +469,18 @@ mod tests {
469469
#[test]
470470
fn times_finished_precise() {
471471
let mut t = Timer::from_seconds(0.01, true);
472-
let duration = Duration::from_secs_f64(1.0 / 3.0);
472+
let duration = Duration::from_secs_f64(0.333);
473473

474+
// total duration: 0.333 => 33 times finished
474475
t.tick(duration);
475476
assert_eq!(t.times_finished(), 33);
477+
// total duration: 0.666 => 33 times finished
476478
t.tick(duration);
477479
assert_eq!(t.times_finished(), 33);
480+
// total duration: 0.999 => 33 times finished
478481
t.tick(duration);
479482
assert_eq!(t.times_finished(), 33);
480-
// It has one additional tick this time to compensate for missing 100th tick
483+
// total duration: 1.332 => 34 times finished
481484
t.tick(duration);
482485
assert_eq!(t.times_finished(), 34);
483486
}

0 commit comments

Comments
 (0)