use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub enum CalculationFormula {
#[serde(rename = "HOECHSTWERT")]
HighestValue,
#[serde(rename = "MINIMALWERT")]
MinimumValue,
#[serde(rename = "MITTELWERT")]
AverageValue,
#[serde(rename = "SUMMENWERT")]
SumValue,
}
impl CalculationFormula {
pub fn german_name(&self) -> &'static str {
match self {
Self::HighestValue => "Höchstwert",
Self::MinimumValue => "Minimalwert",
Self::AverageValue => "Mittelwert",
Self::SumValue => "Summenwert",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_serialize() {
assert_eq!(
serde_json::to_string(&CalculationFormula::HighestValue).unwrap(),
r#""HOECHSTWERT""#
);
}
#[test]
fn test_roundtrip() {
for formula in [
CalculationFormula::HighestValue,
CalculationFormula::MinimumValue,
CalculationFormula::AverageValue,
CalculationFormula::SumValue,
] {
let json = serde_json::to_string(&formula).unwrap();
let parsed: CalculationFormula = serde_json::from_str(&json).unwrap();
assert_eq!(formula, parsed);
}
}
}