| 1 |
|
| 2 |
|
| 3 |
use super::*; |
| 4 |
|
| 5 |
#[test] |
| 6 |
fn macro_average_counts_an_unpredicted_class_as_zero() { |
| 7 |
|
| 8 |
|
| 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 |
|
| 36 |
|
| 37 |
|
| 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 |
|
| 54 |
|
| 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 |
|