|
|
@ -111,6 +111,7 @@ fn next_interval(prev: Instant, now: Instant, interval: Duration) -> Instant {
|
|
|
|
#[cfg(test)]
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
mod test {
|
|
|
|
use super::next_interval;
|
|
|
|
use super::next_interval;
|
|
|
|
|
|
|
|
use std::cmp::Ordering;
|
|
|
|
use std::time::{Duration, Instant};
|
|
|
|
use std::time::{Duration, Instant};
|
|
|
|
|
|
|
|
|
|
|
|
struct Timeline(Instant);
|
|
|
|
struct Timeline(Instant);
|
|
|
@ -134,12 +135,10 @@ mod test {
|
|
|
|
// The math around Instant/Duration isn't 100% precise due to rounding
|
|
|
|
// The math around Instant/Duration isn't 100% precise due to rounding
|
|
|
|
// errors, see #249 for more info
|
|
|
|
// errors, see #249 for more info
|
|
|
|
fn almost_eq(a: Instant, b: Instant) -> bool {
|
|
|
|
fn almost_eq(a: Instant, b: Instant) -> bool {
|
|
|
|
if a == b {
|
|
|
|
match a.cmp(&b) {
|
|
|
|
true
|
|
|
|
Ordering::Equal => true,
|
|
|
|
} else if a > b {
|
|
|
|
Ordering::Greater => a - b < Duration::from_millis(1),
|
|
|
|
a - b < Duration::from_millis(1)
|
|
|
|
Ordering::Less => b - a < Duration::from_millis(1),
|
|
|
|
} else {
|
|
|
|
|
|
|
|
b - a < Duration::from_millis(1)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|