From 0072cda85fe5579fd9d4d90b5cc3407b616787ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Fri, 4 Dec 2020 23:05:04 +0100 Subject: [PATCH] pll: add convergence test --- dsp/src/pll.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dsp/src/pll.rs b/dsp/src/pll.rs index 8cef99b..4156d43 100644 --- a/dsp/src/pll.rs +++ b/dsp/src/pll.rs @@ -74,4 +74,23 @@ mod tests { assert_eq!(y, 0xc2); assert_eq!(f, y); } + + #[test] + fn converge() { + let mut p = PLLState::default(); + let f0 = 0x71f63049_i32; + let shift = 10; + let n = 31 << shift + 2; + let mut x = 0i32; + for i in 0..n { + x = x.wrapping_add(f0); + let (y, f) = p.update(x, shift); + if i > n / 4 { + assert_eq!(f.wrapping_sub(f0).abs() <= 1, true); + } + if i > n / 2 { + assert_eq!(y.wrapping_sub(x).abs() < 1 << 18, true); + } + } + } }