tests(pyargus): add test cases for signals
This commit is contained in:
parent
ab0a2c6d85
commit
137c22cd70
11 changed files with 193 additions and 31 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use argus_core::signals::interpolation::Linear;
|
||||
use argus_core::signals::Signal;
|
||||
use pyo3::prelude::*;
|
||||
|
||||
|
|
@ -83,6 +84,45 @@ macro_rules! impl_signals {
|
|||
self.0.push(Duration::from_secs_f64(time), value)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Check if the signal is empty
|
||||
fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
|
||||
/// The start time of the signal
|
||||
#[getter]
|
||||
fn start_time(&self) -> Option<f64> {
|
||||
use core::ops::Bound::*;
|
||||
match self.0.start_time()? {
|
||||
Included(t) | Excluded(t) => Some(t.as_secs_f64()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The end time of the signal
|
||||
#[getter]
|
||||
fn end_time(&self) -> Option<f64> {
|
||||
use core::ops::Bound::*;
|
||||
match self.0.end_time()? {
|
||||
Included(t) | Excluded(t) => Some(t.as_secs_f64()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the value of the signal at the given time point.
|
||||
///
|
||||
/// If there exists a sample, then the value is returned, otherwise the value is
|
||||
/// interpolated. If the time point lies outside of the domain of the signal, then `None`
|
||||
/// is returned.
|
||||
fn at(self_: PyRef<'_, Self>, time: f64) -> Option<$ty> {
|
||||
let super_ = self_.as_ref();
|
||||
let time = core::time::Duration::from_secs_f64(time);
|
||||
match super_.interpolation {
|
||||
PyInterp::Linear => self_.0.interpolate_at::<Linear>(time),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue