use serrf::{SerrfConfig, normalize};
use serrf_testdata::{SyntheticConfig, generate_dataset};
fn default_synthetic_config() -> SyntheticConfig {
SyntheticConfig {
seed: 42,
..SyntheticConfig::default()
}
}
fn default_serrf_config() -> SerrfConfig {
SerrfConfig {
n_trees: 100,
random_seed: 42,
qc_validation_fraction: 0.2,
..SerrfConfig::default()
}
}
#[test]
fn synthetic_output_shape_matches_input() {
let input = generate_dataset(&default_synthetic_config());
let config = default_serrf_config();
let out = normalize(&input, &config).unwrap();
assert_eq!(out.intensities.data.shape(), input.intensities.data.shape());
}
#[test]
fn synthetic_compounds_normalized_nonzero() {
let input = generate_dataset(&default_synthetic_config());
let config = default_serrf_config();
let out = normalize(&input, &config).unwrap();
assert!(
out.report.compounds_normalized > 0,
"no compounds were normalized"
);
}
#[test]
fn synthetic_qc_rsd_improves() {
let input = generate_dataset(&default_synthetic_config());
let config = default_serrf_config();
let out = normalize(&input, &config).unwrap();
let before = out
.report
.median_qc_train_rsd_before
.expect("no before RSD");
let after = out.report.median_qc_train_rsd_after.expect("no after RSD");
assert!(
after < before,
"QC RSD did not improve: before={before:.4}, after={after:.4}"
);
}
#[test]
fn synthetic_qc_train_improvement_ratio_above_threshold() {
let input = generate_dataset(&default_synthetic_config());
let config = default_serrf_config();
let out = normalize(&input, &config).unwrap();
let ratio = out
.report
.qc_train_rsd_improvement_ratio
.expect("improvement ratio missing");
assert!(
ratio > 1.2,
"QC train RSD improvement ratio too low: {ratio:.3}"
);
}
#[test]
fn synthetic_validate_improvement_ratio_above_threshold() {
let input = generate_dataset(&default_synthetic_config());
let config = default_serrf_config();
let out = normalize(&input, &config).unwrap();
if let Some(ratio) = out.report.qc_validate_rsd_improvement_ratio {
assert!(
ratio > 1.1,
"QC validate RSD improvement ratio too low: {ratio:.3}"
);
}
}