bo4e_core/enums/
calculation_formula.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
11#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
12#[cfg_attr(feature = "json-schema", schemars(rename = "Berechnungsformel"))]
13#[non_exhaustive]
14pub enum CalculationFormula {
15 #[serde(rename = "HOECHSTWERT")]
17 HighestValue,
18
19 #[serde(rename = "MINIMALWERT")]
21 MinimumValue,
22
23 #[serde(rename = "MITTELWERT")]
25 AverageValue,
26
27 #[serde(rename = "SUMMENWERT")]
29 SumValue,
30}
31
32impl CalculationFormula {
33 pub fn german_name(&self) -> &'static str {
35 match self {
36 Self::HighestValue => "Höchstwert",
37 Self::MinimumValue => "Minimalwert",
38 Self::AverageValue => "Mittelwert",
39 Self::SumValue => "Summenwert",
40 }
41 }
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_serialize() {
50 assert_eq!(
51 serde_json::to_string(&CalculationFormula::HighestValue).unwrap(),
52 r#""HOECHSTWERT""#
53 );
54 }
55
56 #[test]
57 fn test_roundtrip() {
58 for formula in [
59 CalculationFormula::HighestValue,
60 CalculationFormula::MinimumValue,
61 CalculationFormula::AverageValue,
62 CalculationFormula::SumValue,
63 ] {
64 let json = serde_json::to_string(&formula).unwrap();
65 let parsed: CalculationFormula = serde_json::from_str(&json).unwrap();
66 assert_eq!(formula, parsed);
67 }
68 }
69}