use crate::gampdf;
pub fn chi2pdf(x: f64, v: f64) -> f64 {
gampdf(x, v / 2.0, 2.0)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_chi2pdf_standard_cases() {
let tol = 1e-14;
assert!((chi2pdf(0.0, 2.0) - 0.5).abs() < tol);
assert!((chi2pdf(2.0, 2.0) - 0.5 * (-1.0f64).exp()).abs() < tol);
assert!((chi2pdf(2.0, 4.0) - 0.5 * (-1.0f64).exp()).abs() < tol);
}
#[test]
fn test_chi2pdf_v1_relation() {
let expected = (1.0 / (2.0 * std::f64::consts::PI).sqrt()) * (-0.5f64).exp();
assert!((chi2pdf(1.0, 1.0) - expected).abs() < 1e-15);
}
#[test]
fn test_chi2pdf_poles_at_zero() {
assert_eq!(chi2pdf(0.0, 1.0), f64::INFINITY);
assert_eq!(chi2pdf(0.0, 2.0), 0.5);
assert_eq!(chi2pdf(0.0, 3.0), 0.0);
}
#[test]
fn test_chi2pdf_invalid_params() {
assert!(chi2pdf(1.0, 0.0) == 0.0);
assert!(chi2pdf(1.0, -1.0).is_nan());
assert!(chi2pdf(f64::NAN, 2.0).is_nan());
assert!(chi2pdf(1.0, f64::NAN).is_nan());
}
#[test]
fn test_chi2pdf_negative_x() {
assert_eq!(chi2pdf(-1.0, 2.0), 0.0);
}
}