|
| 1 | +use rodio::Source; |
| 2 | +use test_support::{TestSource, TestSpan}; |
| 3 | + |
| 4 | +mod test_support; |
| 5 | + |
| 6 | +#[test] |
| 7 | +fn frame_boundray_at_start_of_repeat() { |
| 8 | + let source = TestSource::new() |
| 9 | + .with_span(TestSpan::from_samples((0..10).map(|n| n as f32)).with_sample_count(10)) |
| 10 | + .with_span(TestSpan::from_samples((10..20).map(|n| n as f32)).with_sample_count(10)); |
| 11 | + |
| 12 | + let mut repeating = source.clone().repeat_infinite(); |
| 13 | + repeating.by_ref().take(source.len()).count(); |
| 14 | + assert!(repeating.parameters_changed()); |
| 15 | + |
| 16 | + assert!(repeating.next().is_some()); |
| 17 | + assert!(!repeating.parameters_changed()); |
| 18 | +} |
| 19 | + |
| 20 | +#[test] |
| 21 | +fn parameters_identical_on_second_run() { |
| 22 | + let source = TestSource::new() |
| 23 | + .with_span(TestSpan::from_samples((0..10).map(|n| n as f32)).with_sample_count(10)) |
| 24 | + .with_span(TestSpan::from_samples((10..20).map(|n| n as f32)).with_sample_count(10)); |
| 25 | + |
| 26 | + let mut repeating = source.clone().repeat_infinite(); |
| 27 | + |
| 28 | + let mut first_run_params = Vec::new(); |
| 29 | + let mut second_run_params = Vec::new(); |
| 30 | + |
| 31 | + for params in [&mut first_run_params, &mut second_run_params] { |
| 32 | + for _ in 0..source.len() { |
| 33 | + assert!(repeating.by_ref().next().is_some()); |
| 34 | + params.push(( |
| 35 | + repeating.parameters_changed(), |
| 36 | + repeating.channels(), |
| 37 | + repeating.sample_rate(), |
| 38 | + )); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + assert_eq!(first_run_params, second_run_params); |
| 43 | +} |
| 44 | + |
| 45 | +#[test] |
| 46 | +fn same_samples_on_second_run() { |
| 47 | + let source = TestSource::new() |
| 48 | + .with_span(TestSpan::from_samples((0..10).map(|n| n as f32)).with_sample_count(10)) |
| 49 | + .with_span(TestSpan::from_samples((10..20).map(|n| n as f32)).with_sample_count(10)); |
| 50 | + |
| 51 | + let mut repeating = source.clone().repeat_infinite(); |
| 52 | + let first_run: Vec<_> = repeating.by_ref().take(source.len()).collect(); |
| 53 | + let second_run: Vec<_> = repeating.take(source.len()).collect(); |
| 54 | + |
| 55 | + assert_eq!(first_run, second_run); |
| 56 | +} |
0 commit comments