use feffit::feffdat::gamma;
use std::path::PathBuf;
fn data(name: &str) -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/data")
.join(name)
}
#[test]
fn gamma_matches_scipy() {
let text = std::fs::read_to_string(data("ref_gamma.txt")).unwrap();
let mut max_rel = 0.0f64;
let mut n = 0;
for line in text.lines() {
let line = line.trim();
if line.is_empty() || line.starts_with('#') {
continue;
}
let mut it = line.split_whitespace();
let x: f64 = it.next().unwrap().parse().unwrap();
let want: f64 = it.next().unwrap().parse().unwrap();
let got = gamma(x);
let rel = (got - want).abs() / want.abs();
assert!(
rel < 1e-12,
"gamma({x}) = {got:e}, want {want:e}, rel {rel:e}"
);
max_rel = max_rel.max(rel);
n += 1;
}
assert!(n >= 30, "parsed too few rows: {n}");
eprintln!("gamma: {n} points, max rel err {max_rel:e}");
}