This commit is contained in:
chaos 2024-11-22 17:07:42 +00:00
parent 12b76f3a90
commit aa8e5e0266
4 changed files with 17 additions and 21 deletions

View file

@ -1,8 +1,7 @@
use chrono::{DateTime, TimeZone, Utc};
use rand::Rng;
use crate::types::{
Consumer, CustomUnit, Dose, Estimation, Experience, ExportFormat, Ingestion, StandardDeviation,
CustomUnit, Experience, ExportFormat, Ingestion,
Unit,
};

View file

@ -1,17 +1,14 @@
use std::ops::{Add, Mul};
#[derive(PartialEq, Debug, Copy, Clone)]
#[derive(Default)]
pub enum Estimation {
Precise,
#[default]
Precise,
Estimate,
StandardDeviation(StandardDeviation),
}
impl Default for Estimation {
fn default() -> Self {
Estimation::Precise
}
}
#[derive(PartialEq, Default, Debug, Copy, Clone)]
pub struct StandardDeviation {
@ -46,7 +43,7 @@ impl Add<&Estimation> for Estimation {
Estimation::StandardDeviation(deviation)
}
(_, Estimation::StandardDeviation(deviation)) => {
Estimation::StandardDeviation(deviation.clone())
Estimation::StandardDeviation(*deviation)
}
(Estimation::Estimate, _) | (_, Estimation::Estimate) => Estimation::Estimate,
(Estimation::Precise, Estimation::Precise) => Estimation::Precise,
@ -83,7 +80,7 @@ impl Mul<&Estimation> for Estimation {
Estimation::StandardDeviation(deviation)
}
(_, Estimation::StandardDeviation(deviation)) => {
Estimation::StandardDeviation(deviation.clone())
Estimation::StandardDeviation(*deviation)
}
(Estimation::Estimate, _) | (_, Estimation::Estimate) => Estimation::Estimate,
(Estimation::Precise, Estimation::Precise) => Estimation::Precise,
@ -99,17 +96,17 @@ mod tests {
fn is() {
let deviation = StandardDeviation(Deviation::default());
assert_eq!(Precise.is_precise(), true);
assert_eq!(Precise.is_estimate(), false);
assert_eq!(Precise.is_standard_deviation(), false);
assert!(Precise.is_precise());
assert!(!Precise.is_estimate());
assert!(!Precise.is_standard_deviation());
assert_eq!(Estimate.is_precise(), false);
assert_eq!(Estimate.is_estimate(), true);
assert_eq!(Estimate.is_standard_deviation(), false);
assert!(!Estimate.is_precise());
assert!(Estimate.is_estimate());
assert!(!Estimate.is_standard_deviation());
assert_eq!(deviation.is_precise(), false);
assert_eq!(deviation.is_estimate(), true);
assert_eq!(deviation.is_standard_deviation(), true);
assert!(!deviation.is_precise());
assert!(deviation.is_estimate());
assert!(deviation.is_standard_deviation());
}
#[test]

View file

@ -26,7 +26,7 @@ pub fn parse_consumer_filter(consumer_filter: Option<Vec<String>>) -> Option<Vec
consumer = "default".to_string();
}
consumers.push(Consumer::from(consumer));
consumers.push(Consumer::from(consumer.as_str()));
}
Some(consumers)
}

View file

@ -42,7 +42,7 @@ pub fn format_ingestion_dose(dose: Option<&Dose>, unit: &Unit) -> String {
let dose_per_unit = format_ingestion_dose(unit.dose.as_ref(), &ingestion_unit);
let custom_unit_dose = format_ingestion_dose(Some(&dose), &unit_unit);
let custom_unit_dose = format_ingestion_dose(Some(dose), &unit_unit);
format!("{ingestion_dose} ({dose_per_unit} * {custom_unit_dose})")
}