Skip to content

Commit

Permalink
add (currently unused) init for RustCycle
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Carow authored and Kyle Carow committed Dec 13, 2023
1 parent 933bf7d commit fcb1773
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion rust/fastsim-core/src/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P: AsRef<Path>>(&self, filepath: P) -> anyhow::Result<()> {
let filepath = filepath.as_ref();
let extension = filepath
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit fcb1773

Please sign in to comment.