use super::*;
#[test]
fn test_smoother_convergence() {
let mut smoother = ParamSmoother::new(0.0, 48000.0, 20.0);
smoother.set_target(1.0);
let mut last_val = 0.0;
for _ in 0..1000 {
let current = smoother.tick();
assert!(current >= last_val);
last_val = current;
}
assert!(last_val > 0.5); }
#[test]
fn test_smoother_snap() {
let mut smoother = ParamSmoother::new(0.0, 48000.0, 20.0);
smoother.set_target(1.0);
smoother.snap_to_target();
assert_eq!(smoother.tick(), 1.0);
}
#[test]
fn test_smoother_convergence_high_gain() {
let mut smoother = ParamSmoother::new(0.0, 48000.0, 45.0);
smoother.set_target(3.98);
let mut samples = 0;
for _ in 0..5000 {
let current = smoother.tick();
samples += 1;
if current == 3.98 {
break;
}
}
assert!(
samples <= 2400,
"Convergence took {} samples (expected <= 2400)",
samples
);
}
#[test]
fn test_smoother_denormal_prevention() {
let mut smoother = ParamSmoother::new(1e-20, 48000.0, 20.0);
smoother.set_target(0.0);
let mut converged = false;
for _ in 0..10 {
if smoother.tick() == 0.0 {
converged = true;
break;
}
}
assert!(converged, "Did not converge to 0.0 in 10 iterations");
}
#[test]
fn test_smoother_relative_threshold() {
let mut smoother = ParamSmoother::new(0.0, 48000.0, 20.0);
smoother.set_target(0.001);
let val1 = smoother.tick();
assert!(val1 > 0.0);
assert!(val1 < 0.001);
let mut converged = false;
for _ in 0..5000 {
if smoother.tick() == 0.001 {
converged = true;
break;
}
}
assert!(converged, "Should converge to 0.001");
}