Skip to main content

max / audiofiles

1.7 KB · 59 lines History Blame Raw
1 //! Tests for [`super`].
2
3 use super::*;
4
5 #[test]
6 fn macro_average_counts_an_unpredicted_class_as_zero() {
7 // Skipping it would let a layer raise its macro precision by predicting
8 // a hard class less often, which is backwards.
9 let classes = vec!["a".to_string(), "b".to_string()];
10 let mut counts = BTreeMap::new();
11 counts.insert(
12 "a".to_string(),
13 Counts {
14 tp: 10,
15 fp: 0,
16 fn_: 0,
17 },
18 );
19 counts.insert(
20 "b".to_string(),
21 Counts {
22 tp: 0,
23 fp: 0,
24 fn_: 10,
25 },
26 );
27 assert_eq!(
28 macro_average(&classes, &counts, Counts::precision),
29 Some(0.5)
30 );
31 }
32
33 #[test]
34 fn class_points_score_an_absent_class_as_zero() {
35 // A class missing from a sample's scores is a real zero, not a gap: the
36 // index considered it and gave it no neighbourhood weight. Treating it
37 // as missing would drop true negatives and inflate precision.
38 let p = vec![Prediction {
39 truth: "instrument.drum.kick".into(),
40 top1: Some("instrument.drum.kick".into()),
41 scores: BTreeMap::from([("instrument.drum.kick".to_string(), 0.9)]),
42 fold: 0,
43 origin: "kick".into(),
44 }];
45 let pts = class_points(&p, "instrument.drum.snare");
46 assert_eq!(pts.len(), 1);
47 assert!((pts[0].score - 0.0).abs() < f64::EPSILON);
48 assert!(!pts[0].actual);
49 }
50
51 #[test]
52 fn k_sweep_always_contains_the_runtime_k() {
53 // Safe to set: this test does not read the env, it checks the invariant
54 // the parser must hold whatever the env said.
55 let ks = k_sweep_from_env();
56 assert!(ks.contains(&DEFAULT_K));
57 assert!(ks.windows(2).all(|w| w[0] < w[1]), "sorted and deduped");
58 }
59