use crate::prelude::*;
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
pub enum TimeOff {
Hours(Quantity),
Days(Quantity),
}
impl TimeOff {
pub fn granularity(&self) -> Granularity {
match self {
Self::Hours(_) => Granularity::Hour,
Self::Days(_) => Granularity::Day,
}
}
}
impl std::ops::Deref for TimeOff {
type Target = Quantity;
fn deref(&self) -> &Self::Target {
match self {
Self::Hours(q) => q,
Self::Days(q) => q,
}
}
}
impl HasSample for TimeOff {
fn sample() -> Self {
Self::Days(Quantity::sample())
}
fn sample_other() -> Self {
Self::Hours(Quantity::sample_other())
}
}
#[cfg(test)]
mod tests {
use super::*;
type Sut = TimeOff;
#[test]
fn equality() {
assert_eq!(Sut::sample(), Sut::sample());
assert_eq!(Sut::sample_other(), Sut::sample_other());
}
#[test]
fn inequality() {
assert_ne!(Sut::sample(), Sut::sample_other());
}
#[test]
fn deref() {
let hours = Sut::Hours(Quantity::sample());
let days = Sut::Days(Quantity::sample_other());
assert_eq!(*hours, Quantity::sample());
assert_eq!(*days, Quantity::sample_other());
}
}