use super::tests::run_pipeline_test;
#[test]
#[cfg(feature = "stereo")]
fn test_bypass_no_resampler_stereo() {
let n = 64;
let input_l: Vec<f32> = (0..n).map(|i| i as f32 * 0.01).collect();
let input_r: Vec<f32> = (0..n).map(|i| (i as f32 + 50.0) * 0.01).collect();
let (out_l, out_r) = run_pipeline_test(48000, 48000, &input_l, &input_r, false);
assert_eq!(out_l.len(), n);
assert_eq!(out_r.len(), n);
assert_eq!(
out_l, input_l,
"L channel must be identical to the original"
);
assert_eq!(
out_r, input_r,
"R channel must be identical to the original"
);
}
#[test]
fn test_bypass_no_resampler_mono() {
let n = 64;
let input_l: Vec<f32> = (0..n).map(|i| i as f32 * 0.01).collect();
let input_r = input_l.clone();
let (out_l, out_r) = run_pipeline_test(48000, 48000, &input_l, &input_r, true);
assert_eq!(out_l.len(), n);
assert_eq!(out_r.len(), n);
assert_eq!(out_l, input_l);
assert_eq!(
out_r, input_l,
"In mono mode, the R side must be a copy of L"
);
}
#[test]
#[cfg(feature = "stereo")]
fn test_bypass_with_resampler_stereo() {
let n = 256;
let input_l: Vec<f32> = (0..n).map(|i| (i as f32 * 0.1).sin()).collect();
let input_r: Vec<f32> = (0..n).map(|i| (i as f32 * 0.1 + 0.5).sin()).collect();
let (out_l, _out_r) = run_pipeline_test(44100, 48000, &input_l, &input_r, false);
assert!(!out_l.is_empty());
let mut energy_in = 0.0;
for &x in &input_l {
energy_in += x * x;
}
let mut energy_out = 0.0;
for &x in &out_l {
energy_out += x * x;
}
assert!(
energy_out > energy_in * 0.5,
"The output sound is too weak or silent after conversion"
);
}
#[test]
fn test_bypass_with_resampler_mono() {
let n = 256;
let input_l: Vec<f32> = (0..n).map(|i| (i as f32 * 0.1).sin()).collect();
let input_r = input_l.clone();
let (out_l, out_r) = run_pipeline_test(44100, 48000, &input_l, &input_r, true);
assert!(!out_l.is_empty());
assert_eq!(
out_l, out_r,
"Even with Hz conversion, mono sound must be equal on both sides (L == R)"
);
}