fn curve(freqs: Vec<f64>) -> autoeq::Curve {
let n = freqs.len();
autoeq::Curve {
freq: ndarray::Array1::from(freqs),
spl: ndarray::Array1::zeros(n),
phase: None,
..Default::default()
}
}
#[test]
fn bounds_helper_triggers_when_min_freq_below_data() {
fn reference_check(curve: &autoeq::Curve, min_freq: f64, max_freq: f64) -> (bool, bool) {
let data_min = curve.freq[0];
let data_max = curve.freq[curve.freq.len() - 1];
let log_margin = 0.05;
let min_tol = data_min * 10_f64.powf(-log_margin);
let max_tol = data_max * 10_f64.powf(log_margin);
(min_freq < min_tol, max_freq > max_tol)
}
let c = curve(vec![100.0, 1000.0, 10_000.0]);
let (below, above) = reference_check(&c, 50.0, 5000.0);
assert!(below, "min_freq=50 should trigger below-data warning");
assert!(
!above,
"max_freq=5000 should not trigger above-data warning"
);
let (below, above) = reference_check(&c, 200.0, 20_000.0);
assert!(!below, "min_freq=200 should not trigger below-data warning");
assert!(above, "max_freq=20000 should trigger above-data warning");
let (below, above) = reference_check(&c, 100.0, 10_000.0);
assert!(!below);
assert!(!above);
let (below, above) = reference_check(&c, 99.0, 10_000.0);
assert!(
!below,
"99 Hz vs 100 Hz data_min must be within 5 % log-axis tolerance"
);
assert!(!above);
}
#[test]
fn bounds_helper_handles_empty_curve() {
fn reference_check(curve: &autoeq::Curve, min_freq: f64, max_freq: f64) -> (bool, bool) {
if curve.freq.is_empty() {
return (false, false);
}
let data_min = curve.freq[0];
let data_max = curve.freq[curve.freq.len() - 1];
let log_margin = 0.05;
let min_tol = data_min * 10_f64.powf(-log_margin);
let max_tol = data_max * 10_f64.powf(log_margin);
(min_freq < min_tol, max_freq > max_tol)
}
let empty = curve(vec![]);
let (below, above) = reference_check(&empty, 10.0, 20000.0);
assert!(!below);
assert!(!above);
}