Skip to content
Snippets Groups Projects
Commit 26a5424c authored by Udo Eisenbarth's avatar Udo Eisenbarth :speech_balloon:
Browse files

Uss crate "approx" for unit tests with floats

parent 6be46b86
No related branches found
No related tags found
1 merge request!1Resolve "Spectrum: Add serde serializer / deserializer"
Pipeline #7282 canceled
......@@ -23,6 +23,15 @@ dependencies = [
"libc",
]
[[package]]
name = "approx"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
dependencies = [
"num-traits",
]
[[package]]
name = "autocfg"
version = "1.1.0"
......@@ -594,6 +603,7 @@ checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
name = "opossum"
version = "0.1.0"
dependencies = [
"approx",
"csv",
"ndarray",
"ndarray-stats",
......
......@@ -22,3 +22,5 @@ ndarray= { version="0", features= ["serde"]}
ndarray-stats="0"
csv="1"
plotters="0"
approx = "0" # assert macros for comparison of floats with tolerance
......@@ -504,6 +504,7 @@ pub fn merge_spectra(s1: Option<Spectrum>, s2: Option<Spectrum>) -> Option<Spect
#[cfg(test)]
mod test {
use super::*;
use approx::AbsDiffEq;
use ndarray::array;
fn prep() -> Spectrum {
Spectrum::new(
......@@ -563,7 +564,7 @@ mod test {
assert!(lambdas
.into_iter()
.zip(array![500.0E-9, 501.0E-9, 502.0E-9, 503.0E-9, 504.0E-9, 505.0E-9].iter())
.all(|x| f64::abs(x.0 - *x.1) < 1.0E-16));
.all(|x| x.0.abs_diff_eq(x.1, f64::EPSILON)));
let datas = s.unwrap().data.map(|data| data.1);
assert!(datas
.into_iter()
......@@ -573,7 +574,7 @@ mod test {
4.984E-01,
4.996E-01,
5.010E-01].iter())
.all(|x| f64::abs(x.0 - *x.1) < 1.0E-16))
.all(|x| x.0.abs_diff_eq(x.1, f64::EPSILON)));
}
#[test]
fn from_csv_err() {
......@@ -654,7 +655,7 @@ mod test {
assert!(s
.add_lorentzian_peak(Length::new::<meter>(25.0), Length::new::<meter>(0.5), 2.0)
.is_ok());
assert!(f64::abs(s.total_energy() - 2.0) < 0.1)
assert!(s.total_energy().abs_diff_eq(&2.0, 0.1));
}
#[test]
fn add_lorentzian_wrong_params() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment