diff --git a/rand_distr/src/normal.rs b/rand_distr/src/normal.rs index ae82799147a..4ab0fbd1901 100644 --- a/rand_distr/src/normal.rs +++ b/rand_distr/src/normal.rs @@ -345,7 +345,8 @@ mod tests { assert_almost_eq!(lnorm.norm.std_dev, 1.0, 2e-16); let lnorm = LogNormal::from_mean_cv(e.powf(1.5), (e - 1.0).sqrt()).unwrap(); - assert_eq!((lnorm.norm.mean, lnorm.norm.std_dev), (1.0, 1.0)); + assert!((lnorm.norm.mean - 1.0).abs() < 1e-15); + assert_eq!(lnorm.norm.std_dev, 1.0); } #[test] fn test_log_normal_invalid_sd() { diff --git a/rand_distr/src/pareto.rs b/rand_distr/src/pareto.rs index 217899ed9a7..0c62383b1cb 100644 --- a/rand_distr/src/pareto.rs +++ b/rand_distr/src/pareto.rs @@ -87,6 +87,7 @@ where F: Float, OpenClosed01: Distribution #[cfg(test)] mod tests { use super::*; + use core::fmt::{Debug, Display}; #[test] #[should_panic] @@ -108,21 +109,20 @@ mod tests { #[test] fn value_stability() { - fn test_samples>( - distr: D, zero: F, expected: &[F], + fn test_samples>( + distr: D, thresh: F, expected: &[F], ) { let mut rng = crate::test::rng(213); - let mut buf = [zero; 4]; - for x in &mut buf { - *x = rng.sample(&distr); + for v in expected { + let x = rng.sample(&distr); + assert!((x - *v).abs() < thresh, "not approx eq: {}, {}", x, *v); } - assert_eq!(buf, expected); } - test_samples(Pareto::new(1.0, 1.0).unwrap(), 0f32, &[ + test_samples(Pareto::new(1f32, 1.0).unwrap(), 1e-6, &[ 1.0423688, 2.1235929, 4.132709, 1.4679428, ]); - test_samples(Pareto::new(2.0, 0.5).unwrap(), 0f64, &[ + test_samples(Pareto::new(2.0, 0.5).unwrap(), 1e-14, &[ 9.019295276219136, 4.3097126018270595, 6.837815045397157, diff --git a/rand_distr/tests/value_stability.rs b/rand_distr/tests/value_stability.rs index 986b9963283..525663effc0 100644 --- a/rand_distr/tests/value_stability.rs +++ b/rand_distr/tests/value_stability.rs @@ -339,6 +339,6 @@ fn cauchy_stability() { let expected = [15.023088, -5.446413, 3.7092876, 3.112482]; for &a in expected.iter() { let b = rng.sample(&distr); - assert!((a - b).abs() < 1e-6, "expected: {} = {}", a, b); + assert!((a - b).abs() < 1e-5, "expected: {} = {}", a, b); } }