Restoring len() test, it is actually useful to check
`SampleRateConverter::size_hint()` implementation.
Although its implementation is not precise (see TODOs).
This commit is contained in:
Petr Gladkikh 2024-11-15 19:21:04 +04:00
parent 6734d0178b
commit b6b000b61f

View file

@ -372,6 +372,8 @@ mod test {
let input = vec![2u16, 16, 4, 18, 6, 20, 8, 22]; let input = vec![2u16, 16, 4, 18, 6, 20, 8, 22];
let output = let output =
SampleRateConverter::new(input.into_iter(), SampleRate(2000), SampleRate(3000), 2); SampleRateConverter::new(input.into_iter(), SampleRate(2000), SampleRate(3000), 2);
assert_eq!(output.len(), 12); // Test the source's Iterator::size_hint()
let output = output.collect::<Vec<_>>(); let output = output.collect::<Vec<_>>();
assert_eq!(output, [2, 16, 3, 17, 4, 18, 6, 20, 7, 21, 8, 22]); assert_eq!(output, [2, 16, 3, 17, 4, 18, 6, 20, 7, 21, 8, 22]);
} }
@ -381,7 +383,9 @@ mod test {
let input = vec![1u16, 14]; let input = vec![1u16, 14];
let output = let output =
SampleRateConverter::new(input.into_iter(), SampleRate(1000), SampleRate(7000), 1); SampleRateConverter::new(input.into_iter(), SampleRate(1000), SampleRate(7000), 1);
let size_estimation = output.len();
let output = output.collect::<Vec<_>>(); let output = output.collect::<Vec<_>>();
assert_eq!(output, [1, 2, 4, 6, 8, 10, 12, 14]); assert_eq!(output, [1, 2, 4, 6, 8, 10, 12, 14]);
assert!((size_estimation as f32 / output.len() as f32).abs() < 2.0);
} }
} }