mirror of
https://github.com/RustAudio/rodio
synced 2024-12-05 01:39:15 +00:00
Implemented linear_ramp_seek tests
Also integratd assert_float_eq
This commit is contained in:
parent
78fffb4ec6
commit
e72de34a93
2 changed files with 12 additions and 7 deletions
|
@ -118,6 +118,10 @@ pub use cpal::{
|
|||
SupportedStreamConfig,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
extern crate assert_float_eq;
|
||||
|
||||
mod conversions;
|
||||
mod sink;
|
||||
mod spatial_sink;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std::time::Duration;
|
||||
|
||||
|
||||
use super::SeekError;
|
||||
use crate::{Sample, Source};
|
||||
|
||||
|
@ -169,7 +170,7 @@ mod tests {
|
|||
let source1 = const_source(10, 1.0f32);
|
||||
let mut faded = linear_gain_ramp(source1, Duration::from_secs(4), 0.0, 1.0, true);
|
||||
|
||||
assert_eq!(faded.next(), Some(0.0));
|
||||
assert_float_absolute_eq!(faded.next().unwrap(), 0.0);
|
||||
assert_eq!(faded.next(), Some(0.25));
|
||||
assert_eq!(faded.next(), Some(0.5));
|
||||
assert_eq!(faded.next(), Some(0.75));
|
||||
|
@ -205,13 +206,13 @@ 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_eq!(faded.next(), Some(0.0)); // source value 0
|
||||
assert_eq!(faded.next(), Some(0.04)); // source value 0.4, ramp gain 0.1
|
||||
assert_eq!(faded.next(), Some(0.16)); // source value 0.8, ramp gain 0.2
|
||||
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
|
||||
if let Ok(_result) = faded.try_seek(Duration::from_secs(5)) {
|
||||
assert_eq!(faded.next(), Some(0.64)); // source value 0.8, ramp gain 0.8
|
||||
assert_eq!(faded.next(), Some(0.0)); // source value 0, ramp gain 0.9
|
||||
assert_eq!(faded.next(), Some(0.4)); // source value 0.4. ramp gain 1.0
|
||||
assert_float_absolute_eq!(faded.next().unwrap(), 0.64); // source value 0.8, ramp gain 0.8
|
||||
assert_float_absolute_eq!(faded.next().unwrap(), 0.0); // source value 0, ramp gain 0.9
|
||||
assert_float_absolute_eq!(faded.next().unwrap(), 0.4); // source value 0.4. ramp gain 1.0
|
||||
} else {
|
||||
panic!("try_seek failed!");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue