Skip to content

Commit

Permalink
Switched-out assert_float_eq for approx
Browse files Browse the repository at this point in the history
Different macro library for testing float equality
  • Loading branch information
iluvcapra committed Aug 4, 2024
1 parent 6ba19a6 commit f2f93e6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ pub use crate::stream::{OutputStream, OutputStreamHandle, PlayError, StreamError

#[cfg(test)]
#[macro_use]
extern crate assert_float_eq;
extern crate approx;
24 changes: 12 additions & 12 deletions src/source/linear_ramp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand Down

0 comments on commit f2f93e6

Please sign in to comment.