From fcb17733c830c19aab908aab9918b560be8a6278 Mon Sep 17 00:00:00 2001 From: Kyle Carow Date: Wed, 13 Dec 2023 13:14:58 -0700 Subject: [PATCH] add (currently unused) init for RustCycle --- rust/fastsim-core/src/cycle.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/rust/fastsim-core/src/cycle.rs b/rust/fastsim-core/src/cycle.rs index 132b1a3e..fd84def8 100644 --- a/rust/fastsim-core/src/cycle.rs +++ b/rust/fastsim-core/src/cycle.rs @@ -630,6 +630,25 @@ impl SerdeAPI for RustCycle { const ACCEPTED_BYTE_FORMATS: &'static [&'static str] = &["yaml", "json", "bin", "csv"]; const ACCEPTED_STR_FORMATS: &'static [&'static str] = &["yaml", "json", "csv"]; + // TODO: make this get called somewhere + fn init(&mut self) -> anyhow::Result<()> { + ensure!(!self.is_empty(), "Deserialized cycle is empty"); + let cyc_len = self.len(); + ensure!( + self.mps.len() == cyc_len, + "Length of `mps` does not match length of `time_s`" + ); + ensure!( + self.grade.len() == cyc_len, + "Length of `grade` does not match length of `time_s`" + ); + ensure!( + self.road_type.len() == cyc_len, + "Length of `road_type` does not match length of `time_s`" + ); + Ok(()) + } + fn to_file>(&self, filepath: P) -> anyhow::Result<()> { let filepath = filepath.as_ref(); let extension = filepath @@ -824,11 +843,14 @@ impl RustCycle { } } - #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { self.time_s.len() } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn test_cyc() -> Self { Self { time_s: Array::range(0.0, 10.0, 1.0),