use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub enum Quality {
Full,
Reduced,
Minimal,
}
impl Quality {
#[must_use]
#[inline]
pub fn max_formants(self) -> usize {
match self {
Self::Full => 5,
Self::Reduced => 3,
Self::Minimal => 2,
}
}
#[must_use]
#[inline]
pub fn use_nasal_coupling(self) -> bool {
match self {
Self::Full | Self::Reduced => true,
Self::Minimal => false,
}
}
#[must_use]
#[inline]
pub fn use_subglottal(self) -> bool {
matches!(self, Self::Full)
}
#[must_use]
#[inline]
pub fn use_interaction(self) -> bool {
matches!(self, Self::Full)
}
#[must_use]
#[inline]
pub fn use_lip_radiation(self) -> bool {
match self {
Self::Full | Self::Reduced => true,
Self::Minimal => false,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_quality_formant_counts() {
assert_eq!(Quality::Full.max_formants(), 5);
assert_eq!(Quality::Reduced.max_formants(), 3);
assert_eq!(Quality::Minimal.max_formants(), 2);
}
#[test]
fn test_quality_feature_flags() {
assert!(Quality::Full.use_nasal_coupling());
assert!(Quality::Full.use_subglottal());
assert!(Quality::Full.use_interaction());
assert!(Quality::Full.use_lip_radiation());
assert!(Quality::Reduced.use_nasal_coupling());
assert!(!Quality::Reduced.use_subglottal());
assert!(!Quality::Reduced.use_interaction());
assert!(Quality::Reduced.use_lip_radiation());
assert!(!Quality::Minimal.use_nasal_coupling());
assert!(!Quality::Minimal.use_subglottal());
assert!(!Quality::Minimal.use_interaction());
assert!(!Quality::Minimal.use_lip_radiation());
}
#[test]
fn test_serde_roundtrip() {
for quality in [Quality::Full, Quality::Reduced, Quality::Minimal] {
let json = serde_json::to_string(&quality).unwrap();
let q2: Quality = serde_json::from_str(&json).unwrap();
assert_eq!(q2, quality);
}
}
}