diff --git a/russell_ode/src/output.rs b/russell_ode/src/output.rs index 5888f042..116f0c35 100644 --- a/russell_ode/src/output.rs +++ b/russell_ode/src/output.rs @@ -389,7 +389,7 @@ impl<'a, A> Output<'a, A> { if self.with_dense_output() { if let Some(h_out) = self.dense_h_out { // uniform spacing - let n = ((x1 - x0) / h_out) as usize + 1; + let n = usize::max(2, ((x1 - x0) / h_out) as usize + 1); // at least 2 (first and last) are required if self.dense_x.len() != n { self.dense_x.resize(n, 0.0); } @@ -808,6 +808,14 @@ mod tests { assert_eq!(y0_out.len(), 4); } + #[test] + fn initialize_with_dense_output_works_at_least_two_stations() { + let mut out = Output::<'_, NoArgs>::new(); + out.set_dense_h_out(0.5).unwrap().set_dense_recording(&[0]); + out.initialize(0.99, 1.0, false).unwrap(); + assert_eq!(out.dense_x.len(), 2); + } + #[test] fn initialize_with_step_output_works() { let mut out = Output::<'_, NoArgs>::new();