use super::TimePoint;
use core::fmt::{self, Debug};
#[derive(Clone, Copy, Default, PartialEq, Eq)]
pub struct TimeSpan {
pub start: TimePoint,
pub end: TimePoint,
}
impl TimeSpan {
#[must_use]
pub const fn new(start: TimePoint, end: TimePoint) -> Self {
Self { start, end }
}
}
impl Debug for TimeSpan {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?} --> {:?}", self.start, self.end)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn time_span_creation() {
assert_eq!(
TimeSpan::new(TimePoint::from_msecs(0), TimePoint::from_secs(1.34)),
TimeSpan {
start: TimePoint::from_msecs(0),
end: TimePoint::from_secs(1.34)
}
);
}
#[test]
fn time_span_equality() {
let time_span_0_1 = TimeSpan::new(TimePoint::from_msecs(0), TimePoint::from_secs(1.34));
let time_span_1_2 = TimeSpan::new(TimePoint::from_msecs(1245), TimePoint::from_secs(2.34));
assert_eq!(
time_span_0_1,
TimeSpan::new(TimePoint::from_msecs(0), TimePoint::from_secs(1.34))
);
assert_eq!(
time_span_1_2,
TimeSpan {
start: TimePoint::from_msecs(1245),
end: TimePoint::from_secs(2.34)
}
);
}
#[test]
fn time_span_nequality() {
let time_span_0_1 = TimeSpan::new(TimePoint::from_msecs(0), TimePoint::from_secs(1.34));
let time_span_0_2 = TimeSpan::new(TimePoint::from_msecs(0), TimePoint::from_secs(2.34));
let time_span_1_2 = TimeSpan::new(TimePoint::from_msecs(1245), TimePoint::from_secs(2.34));
assert_ne!(time_span_0_1, time_span_0_2);
assert_ne!(time_span_0_2, time_span_1_2);
}
}