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
This commit is contained in:
François 2022-01-28 16:17:54 +00:00 committed by Carter Anderson
parent ef5c8e83ad
commit 31af9d4ee1

View file

@ -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);
}