Skip to content

Commit 69a840a

Browse files
committed
move crossfade tests to integration tests
1 parent 42c5eec commit 69a840a

File tree

2 files changed

+39
-47
lines changed

2 files changed

+39
-47
lines changed

src/source/crossfade.rs

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::time::Duration;
77
///
88
/// Only the crossfaded portion (beginning of fadeout, beginning of fadein) is
99
/// returned.
10-
pub fn crossfade<I1, I2>(
10+
pub(crate) fn crossfade<I1, I2>(
1111
input_fadeout: I1,
1212
input_fadein: I2,
1313
duration: Duration,
@@ -28,49 +28,3 @@ where
2828
/// Only the crossfaded portion (beginning of fadeout, beginning of fadein) is
2929
/// covered.
3030
pub type Crossfade<I1, I2> = Mix<TakeDuration<I1>, FadeIn<TakeDuration<I2>>>;
31-
32-
#[cfg(test)]
33-
mod tests {
34-
use super::*;
35-
use crate::buffer::SamplesBuffer;
36-
use crate::source::Zero;
37-
38-
fn dummy_source(length: u8) -> SamplesBuffer {
39-
let data: Vec<f32> = (1..=length).map(f32::from).collect();
40-
SamplesBuffer::new(1, 1, data)
41-
}
42-
43-
#[test]
44-
fn test_crossfade_with_self() {
45-
let source1 = dummy_source(10);
46-
let source2 = dummy_source(10);
47-
let mut mixed = crossfade(
48-
source1,
49-
source2,
50-
Duration::from_secs(5) + Duration::from_nanos(1),
51-
);
52-
assert_eq!(mixed.next(), Some(1.0));
53-
assert_eq!(mixed.next(), Some(2.0));
54-
assert_eq!(mixed.next(), Some(3.0));
55-
assert_eq!(mixed.next(), Some(4.0));
56-
assert_eq!(mixed.next(), Some(5.0));
57-
assert_eq!(mixed.next(), None);
58-
}
59-
60-
#[test]
61-
fn test_crossfade() {
62-
let source1 = dummy_source(10);
63-
let source2 = Zero::new(1, 1);
64-
let mixed = crossfade(
65-
source1,
66-
source2,
67-
Duration::from_secs(5) + Duration::from_nanos(1),
68-
);
69-
let result = mixed.collect::<Vec<_>>();
70-
assert_eq!(result.len(), 5);
71-
assert!(result
72-
.iter()
73-
.zip(vec![1.0, 2.0 * 0.8, 3.0 * 0.6, 4.0 * 0.4, 5.0 * 0.2])
74-
.all(|(a, b)| (a - b).abs() < 1e-6));
75-
}
76-
}

tests/crossfade.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use std::time::Duration;
2+
3+
use rodio::buffer::SamplesBuffer;
4+
use rodio::source::Zero;
5+
use rodio::Source;
6+
7+
fn dummy_source(length: u8) -> SamplesBuffer {
8+
let data: Vec<f32> = (1..=length).map(f32::from).collect();
9+
SamplesBuffer::new(1, 1, data)
10+
}
11+
12+
#[test]
13+
fn test_crossfade_with_self() {
14+
let source1 = dummy_source(10);
15+
let source2 = dummy_source(10);
16+
let mut mixed =
17+
source1.take_crossfade_with(source2, Duration::from_secs(5) + Duration::from_nanos(1));
18+
assert_eq!(mixed.next(), Some(1.0));
19+
assert_eq!(mixed.next(), Some(2.0));
20+
assert_eq!(mixed.next(), Some(3.0));
21+
assert_eq!(mixed.next(), Some(4.0));
22+
assert_eq!(mixed.next(), Some(5.0));
23+
assert_eq!(mixed.next(), None);
24+
}
25+
26+
#[test]
27+
fn test_crossfade() {
28+
let source1 = dummy_source(10);
29+
let source2 = Zero::new(1, 1);
30+
let mixed =
31+
source1.take_crossfade_with(source2, Duration::from_secs(5) + Duration::from_nanos(1));
32+
let result = mixed.collect::<Vec<_>>();
33+
assert_eq!(result.len(), 5);
34+
assert!(result
35+
.iter()
36+
.zip(vec![1.0, 2.0 * 0.8, 3.0 * 0.6, 4.0 * 0.4, 5.0 * 0.2])
37+
.all(|(a, b)| (a - b).abs() < 1e-6));
38+
}

0 commit comments

Comments
 (0)