Skip to content

Commit dd77d1c

Browse files
committed
Lower precision of tests where required
1 parent 55d9830 commit dd77d1c

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

rand_distr/src/normal.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ mod tests {
345345
assert_almost_eq!(lnorm.norm.std_dev, 1.0, 2e-16);
346346

347347
let lnorm = LogNormal::from_mean_cv(e.powf(1.5), (e - 1.0).sqrt()).unwrap();
348-
assert_eq!((lnorm.norm.mean, lnorm.norm.std_dev), (1.0, 1.0));
348+
assert!((lnorm.norm.mean - 1.0).abs() < 1e-15);
349+
assert_eq!(lnorm.norm.std_dev, 1.0);
349350
}
350351
#[test]
351352
fn test_log_normal_invalid_sd() {

rand_distr/src/pareto.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ where F: Float, OpenClosed01: Distribution<F>
8787
#[cfg(test)]
8888
mod tests {
8989
use super::*;
90+
use core::fmt::{Debug, Display};
9091

9192
#[test]
9293
#[should_panic]
@@ -108,21 +109,20 @@ mod tests {
108109

109110
#[test]
110111
fn value_stability() {
111-
fn test_samples<F: Float + core::fmt::Debug, D: Distribution<F>>(
112-
distr: D, zero: F, expected: &[F],
112+
fn test_samples<F: Float + Debug + Display, D: Distribution<F>>(
113+
distr: D, thresh: F, expected: &[F],
113114
) {
114115
let mut rng = crate::test::rng(213);
115-
let mut buf = [zero; 4];
116-
for x in &mut buf {
117-
*x = rng.sample(&distr);
116+
for v in expected {
117+
let x = rng.sample(&distr);
118+
assert!((x - *v).abs() < thresh, "not approx eq: {}, {}", x, *v);
118119
}
119-
assert_eq!(buf, expected);
120120
}
121121

122-
test_samples(Pareto::new(1.0, 1.0).unwrap(), 0f32, &[
122+
test_samples(Pareto::new(1f32, 1.0).unwrap(), 1e-6, &[
123123
1.0423688, 2.1235929, 4.132709, 1.4679428,
124124
]);
125-
test_samples(Pareto::new(2.0, 0.5).unwrap(), 0f64, &[
125+
test_samples(Pareto::new(2.0, 0.5).unwrap(), 1e-14, &[
126126
9.019295276219136,
127127
4.3097126018270595,
128128
6.837815045397157,

rand_distr/tests/value_stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,6 @@ fn cauchy_stability() {
339339
let expected = [15.023088, -5.446413, 3.7092876, 3.112482];
340340
for &a in expected.iter() {
341341
let b = rng.sample(&distr);
342-
assert!((a - b).abs() < 1e-6, "expected: {} = {}", a, b);
342+
assert!((a - b).abs() < 1e-5, "expected: {} = {}", a, b);
343343
}
344344
}

0 commit comments

Comments
 (0)