//! Tests for [`super`]. use super::*; #[test] fn macro_average_counts_an_unpredicted_class_as_zero() { // Skipping it would let a layer raise its macro precision by predicting // a hard class less often, which is backwards. let classes = vec!["a".to_string(), "b".to_string()]; let mut counts = BTreeMap::new(); counts.insert( "a".to_string(), Counts { tp: 10, fp: 0, fn_: 0, }, ); counts.insert( "b".to_string(), Counts { tp: 0, fp: 0, fn_: 10, }, ); assert_eq!( macro_average(&classes, &counts, Counts::precision), Some(0.5) ); } #[test] fn class_points_score_an_absent_class_as_zero() { // A class missing from a sample's scores is a real zero, not a gap: the // index considered it and gave it no neighbourhood weight. Treating it // as missing would drop true negatives and inflate precision. let p = vec![Prediction { truth: "instrument.drum.kick".into(), top1: Some("instrument.drum.kick".into()), scores: BTreeMap::from([("instrument.drum.kick".to_string(), 0.9)]), fold: 0, origin: "kick".into(), }]; let pts = class_points(&p, "instrument.drum.snare"); assert_eq!(pts.len(), 1); assert!((pts[0].score - 0.0).abs() < f64::EPSILON); assert!(!pts[0].actual); } #[test] fn k_sweep_always_contains_the_runtime_k() { // Safe to set: this test does not read the env, it checks the invariant // the parser must hold whatever the env said. let ks = k_sweep_from_env(); assert!(ks.contains(&DEFAULT_K)); assert!(ks.windows(2).all(|w| w[0] < w[1]), "sorted and deduped"); }