Skip to main content

qualia_audio/
capability_registry_helpers.rs

1//! Helper functions, lookups, and unit tests for the audio capability registry.
2
3use super::*;
4
5/// Look up a capability by id.
6pub fn by_id(id: &str) -> Option<&'static AudioCapability> {
7    CAPABILITIES.iter().find(|c| c.id == id)
8}
9
10/// Count rows with a given status.
11pub fn count_by_status(status: CapabilityStatus) -> usize {
12    CAPABILITIES.iter().filter(|c| c.status == status).count()
13}
14
15#[cfg(test)]
16mod tests {
17    use super::*;
18
19    #[test]
20    fn ids_are_unique() {
21        for (i, a) in CAPABILITIES.iter().enumerate() {
22            for b in &CAPABILITIES[i + 1..] {
23                assert_ne!(a.id, b.id, "duplicate capability id: {}", a.id);
24            }
25        }
26    }
27
28    #[test]
29    fn present_rows_are_real() {
30        // A Present row must not describe itself as a placeholder/fake.
31        for c in CAPABILITIES.iter().filter(|c| c.status == Present) {
32            let n = c.note.to_ascii_lowercase();
33            assert!(
34                !n.contains("fake") && !n.contains("placeholder") && !n.contains("not "),
35                "Present row {} has a non-real note: {}",
36                c.id,
37                c.note
38            );
39        }
40    }
41
42    #[test]
43    fn lookup_works() {
44        assert_eq!(by_id("vocoder").map(|c| c.status), Some(NeedsWeights));
45        assert_eq!(by_id("energy_rms").map(|c| c.status), Some(Present));
46        assert_eq!(by_id("mfcc").map(|c| c.status), Some(Present));
47        assert!(by_id("nonexistent").is_none());
48    }
49
50    #[test]
51    fn progress_and_remaining_are_both_honest() {
52        // Waves 0–3 have landed real algorithms; later waves + gated learned heads remain.
53        assert!(
54            count_by_status(Present) >= 50,
55            "expected substantial Present coverage"
56        );
57        assert!(
58            count_by_status(NeedsWeights) >= 5,
59            "principal-gated learned heads (AED/speech/CREPE/vocoder/MOS) must read as NeedsWeights"
60        );
61    }
62}