mod common;
use rosa::matrix::{Aggregate, Matrix, sync};
#[test]
fn test_sync_mean_matches_librosa() {
let ref_data = common::load_audio_reference("sync.json");
let rows = ref_data["input_rows"].as_u64().unwrap() as usize;
let cols = ref_data["input_cols"].as_u64().unwrap() as usize;
let input_flat: Vec<f64> = serde_json::from_value(ref_data["input"].clone()).unwrap();
let input = Matrix::from_vec(input_flat, rows, cols);
let frames: Vec<usize> = serde_json::from_value::<Vec<u64>>(ref_data["frames"].clone())
.unwrap()
.into_iter()
.map(|f| f as usize)
.collect();
let expected_rows = ref_data["mean_rows"].as_u64().unwrap() as usize;
let expected_cols = ref_data["mean_cols"].as_u64().unwrap() as usize;
let expected: Vec<f64> = serde_json::from_value(ref_data["mean"].clone()).unwrap();
let result = sync(&input, &frames, Aggregate::Mean);
assert_eq!(
result.shape(),
(expected_rows, expected_cols),
"sync mean shape mismatch"
);
common::assert_approx_eq(result.as_slice(), &expected, 1e-10, "sync_mean");
}
#[test]
fn test_sync_median_matches_librosa() {
let ref_data = common::load_audio_reference("sync.json");
let rows = ref_data["input_rows"].as_u64().unwrap() as usize;
let cols = ref_data["input_cols"].as_u64().unwrap() as usize;
let input_flat: Vec<f64> = serde_json::from_value(ref_data["input"].clone()).unwrap();
let input = Matrix::from_vec(input_flat, rows, cols);
let frames: Vec<usize> = serde_json::from_value::<Vec<u64>>(ref_data["frames"].clone())
.unwrap()
.into_iter()
.map(|f| f as usize)
.collect();
let expected_rows = ref_data["median_rows"].as_u64().unwrap() as usize;
let expected_cols = ref_data["median_cols"].as_u64().unwrap() as usize;
let expected: Vec<f64> = serde_json::from_value(ref_data["median"].clone()).unwrap();
let result = sync(&input, &frames, Aggregate::Median);
assert_eq!(
result.shape(),
(expected_rows, expected_cols),
"sync median shape mismatch"
);
common::assert_approx_eq(result.as_slice(), &expected, 1e-10, "sync_median");
}