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