From f2f93e69470d21de1f6e27e282bcfd1a8c84d202 Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Sun, 4 Aug 2024 16:40:39 -0700 Subject: [PATCH] Switched-out assert_float_eq for approx Different macro library for testing float equality --- Cargo.toml | 2 +- src/lib.rs | 2 +- src/source/linear_ramp.rs | 24 ++++++++++++------------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9f84cc7..aa75167 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ symphonia-aiff = ["symphonia/aiff", "symphonia/pcm"] quickcheck = "0.9.2" rstest = "0.18.2" rstest_reuse = "0.6.0" -assert_float_eq = "1.1.3" +approx = "0.5.1" [[example]] name = "music_m4a" diff --git a/src/lib.rs b/src/lib.rs index a94bbd4..0c86ba9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -139,4 +139,4 @@ pub use crate::stream::{OutputStream, OutputStreamHandle, PlayError, StreamError #[cfg(test)] #[macro_use] -extern crate assert_float_eq; +extern crate approx; diff --git a/src/source/linear_ramp.rs b/src/source/linear_ramp.rs index 5349f8e..5be8b39 100644 --- a/src/source/linear_ramp.rs +++ b/src/source/linear_ramp.rs @@ -205,30 +205,30 @@ mod tests { let source1 = cycle_source(20, vec![0.0f32, 0.4f32, 0.8f32]); let mut faded = linear_gain_ramp(source1, Duration::from_secs(10), 0.0, 1.0, true); - assert_float_absolute_eq!(faded.next().unwrap(), 0.0); // source value 0 - assert_float_absolute_eq!(faded.next().unwrap(), 0.04); // source value 0.4, ramp gain 0.1 - assert_float_absolute_eq!(faded.next().unwrap(), 0.16); // source value 0.8, ramp gain 0.2 + assert_abs_diff_eq!(faded.next().unwrap(), 0.0); // source value 0 + assert_abs_diff_eq!(faded.next().unwrap(), 0.04); // source value 0.4, ramp gain 0.1 + assert_abs_diff_eq!(faded.next().unwrap(), 0.16); // source value 0.8, ramp gain 0.2 if let Ok(_result) = faded.try_seek(Duration::from_secs(5)) { - assert_float_absolute_eq!(faded.next().unwrap(), 0.40); // source value 0.8, ramp gain 0.5 - assert_float_absolute_eq!(faded.next().unwrap(), 0.0); // source value 0, ramp gain 0.6 - assert_float_absolute_eq!(faded.next().unwrap(), 0.28); // source value 0.4. ramp gain 0.7 + assert_abs_diff_eq!(faded.next().unwrap(), 0.40); // source value 0.8, ramp gain 0.5 + assert_abs_diff_eq!(faded.next().unwrap(), 0.0); // source value 0, ramp gain 0.6 + assert_abs_diff_eq!(faded.next().unwrap(), 0.28); // source value 0.4. ramp gain 0.7 } else { panic!("try_seek() failed!"); } if let Ok(_result) = faded.try_seek(Duration::from_secs(0)) { - assert_float_absolute_eq!(faded.next().unwrap(), 0.0); // source value 0, ramp gain 0.0 - assert_float_absolute_eq!(faded.next().unwrap(), 0.04); // source value 0.4, ramp gain 0.1 - assert_float_absolute_eq!(faded.next().unwrap(), 0.16); // source value 0.8. ramp gain 0.2 + assert_abs_diff_eq!(faded.next().unwrap(), 0.0); // source value 0, ramp gain 0.0 + assert_abs_diff_eq!(faded.next().unwrap(), 0.04); // source value 0.4, ramp gain 0.1 + assert_abs_diff_eq!(faded.next().unwrap(), 0.16); // source value 0.8. ramp gain 0.2 } else { panic!("try_seek() failed!"); } if let Ok(_result) = faded.try_seek(Duration::from_secs(10)) { - assert_float_absolute_eq!(faded.next().unwrap(), 0.4); // source value 0.4, ramp gain 1.0 - assert_float_absolute_eq!(faded.next().unwrap(), 0.8); // source value 0.8, ramp gain 1.0 - assert_float_absolute_eq!(faded.next().unwrap(), 0.0); // source value 0. ramp gain 1.0 + assert_abs_diff_eq!(faded.next().unwrap(), 0.4); // source value 0.4, ramp gain 1.0 + assert_abs_diff_eq!(faded.next().unwrap(), 0.8); // source value 0.8, ramp gain 1.0 + assert_abs_diff_eq!(faded.next().unwrap(), 0.0); // source value 0. ramp gain 1.0 } else { panic!("try_seek() failed!"); }