From 19cb8e1ef012126aa7e019ffadd5391dd9470468 Mon Sep 17 00:00:00 2001 From: Matt McPherrin <git@mcpherrin.ca> Date: Wed, 15 Jul 2015 21:04:27 -0700 Subject: [PATCH] Finish test so it actually tests something useful. --- src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index d21bf6f..c0f28e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ // This (implicitly/naively) uses a rectangular window. Some way to set up a window function // will be needed probably -- if mutating your samples before calling this isn't sufficient. use std::f32; +use std::f32::consts::PI; /// Set up parameters (and some precomputed values for those). #[derive(Clone, Copy)] @@ -75,7 +76,7 @@ fn one_sine() { let step = 1. / 8000.; for sample in (0 .. 8000) { let time = sample as f32 * step; - buf[sample] = ( time * 1800. * 2. * f32::consts::PI ).sin() as i16 + buf[sample] = ((time * 1800. * 2. * PI).sin()*std::i16::MAX as f32) as i16; } let p = Parameters::new(1800., 8000., 256); @@ -85,6 +86,9 @@ fn one_sine() { let p = Parameters::new(freq, 8000., 256); let mag = p.start().add(&buf[0..256]).finish_mag(); println!("{}: {}", freq, mag); + if freq != 1800. { + assert!(mag1800 > 10.*mag); + } } } -- GitLab