From aa8e5e0266d456e0856486964ea9ecd552283492 Mon Sep 17 00:00:00 2001 From: chaos Date: Fri, 22 Nov 2024 17:07:42 +0000 Subject: [PATCH] update --- journal/src/journal.rs | 3 +- journal/src/types/estimate.rs | 31 +++++++++----------- journal_cli/src/commands/print_experience.rs | 2 +- journal_cli/src/formatting.rs | 2 +- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/journal/src/journal.rs b/journal/src/journal.rs index 13663a0..87fba26 100644 --- a/journal/src/journal.rs +++ b/journal/src/journal.rs @@ -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, }; diff --git a/journal/src/types/estimate.rs b/journal/src/types/estimate.rs index eb1a606..42f7947 100644 --- a/journal/src/types/estimate.rs +++ b/journal/src/types/estimate.rs @@ -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] diff --git a/journal_cli/src/commands/print_experience.rs b/journal_cli/src/commands/print_experience.rs index 6da5ac6..ae43c5c 100644 --- a/journal_cli/src/commands/print_experience.rs +++ b/journal_cli/src/commands/print_experience.rs @@ -26,7 +26,7 @@ pub fn parse_consumer_filter(consumer_filter: Option>) -> Option, 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})") }