From 36a9e69b6a5504b8eb61dfd450a3de9e7b983208 Mon Sep 17 00:00:00 2001 From: Orion Yeung <11580988+orionyeung001@users.noreply.github.com> Date: Sun, 21 Apr 2024 17:46:17 -0500 Subject: [PATCH] test: ensure test suite matches behavior for restricting bounded Uniform --- src/distribution/uniform.rs | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/src/distribution/uniform.rs b/src/distribution/uniform.rs index 46d116f2..ce419cfd 100644 --- a/src/distribution/uniform.rs +++ b/src/distribution/uniform.rs @@ -288,19 +288,19 @@ mod tests { #[test] fn test_create() { - create_case(0.0, 0.0); create_case(0.0, 0.1); create_case(0.0, 1.0); - create_case(10.0, 10.0); create_case(-5.0, 11.0); create_case(-5.0, 100.0); } #[test] fn test_bad_create() { + bad_create_case(0.0, 0.0); bad_create_case(f64::NAN, 1.0); bad_create_case(1.0, f64::NAN); bad_create_case(f64::NAN, f64::NAN); + bad_create_case(0.0, f64::INFINITY); bad_create_case(1.0, 0.0); } @@ -311,7 +311,6 @@ mod tests { test_case(0.0, 2.0, 1.0 / 3.0, variance); test_almost(0.1, 4.0, 1.2675, 1e-15, variance); test_case(10.0, 11.0, 1.0 / 12.0, variance); - test_case(0.0, f64::INFINITY, f64::INFINITY, variance); } #[test] @@ -322,7 +321,6 @@ mod tests { test_almost(0.1, 4.0, 1.360976553135600743431, 1e-15, entropy); test_case(1.0, 10.0, 2.19722457733621938279, entropy); test_case(10.0, 11.0, 0.0, entropy); - test_case(0.0, f64::INFINITY, f64::INFINITY, entropy); } #[test] @@ -333,7 +331,6 @@ mod tests { test_case(0.1, 4.0, 0.0, skewness); test_case(1.0, 10.0, 0.0, skewness); test_case(10.0, 11.0, 0.0, skewness); - test_case(0.0, f64::INFINITY, 0.0, skewness); } #[test] @@ -344,7 +341,6 @@ mod tests { test_case(0.1, 4.0, 2.05, mode); test_case(1.0, 10.0, 5.5, mode); test_case(10.0, 11.0, 10.5, mode); - test_case(0.0, f64::INFINITY, f64::INFINITY, mode); } #[test] @@ -355,15 +351,11 @@ mod tests { test_case(0.1, 4.0, 2.05, median); test_case(1.0, 10.0, 5.5, median); test_case(10.0, 11.0, 10.5, median); - test_case(0.0, f64::INFINITY, f64::INFINITY, median); } #[test] fn test_pdf() { let pdf = |arg: f64| move |x: Uniform| x.pdf(arg); - test_case(0.0, 0.0, 0.0, pdf(-5.0)); - test_case(0.0, 0.0, f64::INFINITY, pdf(0.0)); - test_case(0.0, 0.0, 0.0, pdf(5.0)); test_case(0.0, 0.1, 0.0, pdf(-5.0)); test_case(0.0, 0.1, 10.0, pdf(0.05)); test_case(0.0, 0.1, 0.0, pdf(5.0)); @@ -378,17 +370,11 @@ mod tests { test_case(-5.0, 100.0, 0.009523809523809523809524, pdf(-5.0)); test_case(-5.0, 100.0, 0.009523809523809523809524, pdf(0.0)); test_case(-5.0, 100.0, 0.0, pdf(101.0)); - test_case(0.0, f64::INFINITY, 0.0, pdf(-5.0)); - test_case(0.0, f64::INFINITY, 0.0, pdf(10.0)); - test_case(0.0, f64::INFINITY, 0.0, pdf(f64::INFINITY)); } #[test] fn test_ln_pdf() { let ln_pdf = |arg: f64| move |x: Uniform| x.ln_pdf(arg); - test_case(0.0, 0.0, f64::NEG_INFINITY, ln_pdf(-5.0)); - test_case(0.0, 0.0, f64::INFINITY, ln_pdf(0.0)); - test_case(0.0, 0.0, f64::NEG_INFINITY, ln_pdf(5.0)); test_case(0.0, 0.1, f64::NEG_INFINITY, ln_pdf(-5.0)); test_almost(0.0, 0.1, 2.302585092994045684018, 1e-15, ln_pdf(0.05)); test_case(0.0, 0.1, f64::NEG_INFINITY, ln_pdf(5.0)); @@ -403,23 +389,17 @@ mod tests { test_case(-5.0, 100.0, -4.653960350157523371101, ln_pdf(-5.0)); test_case(-5.0, 100.0, -4.653960350157523371101, ln_pdf(0.0)); test_case(-5.0, 100.0, f64::NEG_INFINITY, ln_pdf(101.0)); - test_case(0.0, f64::INFINITY, f64::NEG_INFINITY, ln_pdf(-5.0)); - test_case(0.0, f64::INFINITY, f64::NEG_INFINITY, ln_pdf(10.0)); - test_case(0.0, f64::INFINITY, f64::NEG_INFINITY, ln_pdf(f64::INFINITY)); } #[test] fn test_cdf() { let cdf = |arg: f64| move |x: Uniform| x.cdf(arg); - test_case(0.0, 0.0, 0.0, cdf(0.0)); test_case(0.0, 0.1, 0.5, cdf(0.05)); test_case(0.0, 1.0, 0.5, cdf(0.5)); test_case(0.0, 10.0, 0.1, cdf(1.0)); test_case(0.0, 10.0, 0.5, cdf(5.0)); test_case(-5.0, 100.0, 0.0, cdf(-5.0)); test_case(-5.0, 100.0, 0.04761904761904761904762, cdf(0.0)); - test_case(0.0, f64::INFINITY, 0.0, cdf(10.0)); - test_case(0.0, f64::INFINITY, 1.0, cdf(f64::INFINITY)); } #[test] @@ -438,15 +418,12 @@ mod tests { #[test] fn test_sf() { let sf = |arg: f64| move |x: Uniform| x.sf(arg); - test_case(0.0, 0.0, 1.0, sf(0.0)); test_case(0.0, 0.1, 0.5, sf(0.05)); test_case(0.0, 1.0, 0.5, sf(0.5)); test_case(0.0, 10.0, 0.9, sf(1.0)); test_case(0.0, 10.0, 0.5, sf(5.0)); test_case(-5.0, 100.0, 1.0, sf(-5.0)); test_case(-5.0, 100.0, 0.9523809523809523, sf(0.0)); - test_case(0.0, f64::INFINITY, 1.0, sf(10.0)); - test_case(0.0, f64::INFINITY, 0.0, sf(f64::INFINITY)); } #[test]