#[derive(
Clone,
Copy,
Debug,
Eq,
Hash,
PartialEq,
strum_macros::AsRefStr,
strum_macros::EnumString,
strum_macros::IntoStaticStr,
)]
#[strum(ascii_case_insensitive)]
pub enum HumidAirParam {
#[strum(
to_string = "B",
serialize = "Twb",
serialize = "T_wb",
serialize = "WetBulb",
serialize = "TWetBulb"
)]
TWetBulb,
#[strum(to_string = "C", serialize = "Cp", serialize = "Cpda", serialize = "Cp_da")]
Cpda,
#[strum(to_string = "Cha", serialize = "Cpha", serialize = "Cp_ha")]
Cpha,
#[strum(to_string = "CV", serialize = "Cvda", serialize = "Cv_da")]
Cvda,
#[strum(to_string = "CVha", serialize = "Cv_ha")]
Cvha,
#[strum(
to_string = "D",
serialize = "Tdp",
serialize = "T_dp",
serialize = "DewPoint",
serialize = "TDew"
)]
TDew,
#[strum(to_string = "H", serialize = "Hda", serialize = "H_da", serialize = "Enthalpy")]
Hda,
#[strum(to_string = "Hha", serialize = "H_ha")]
Hha,
#[strum(to_string = "K", serialize = "Conductivity")]
Conductivity,
#[strum(
to_string = "M",
serialize = "Visc",
serialize = "mu",
serialize = "viscosity",
serialize = "DynamicViscosity"
)]
DynamicViscosity,
#[strum(to_string = "psi_w", serialize = "Y", serialize = "PsiW")]
PsiW,
#[strum(to_string = "P", serialize = "Pressure")]
P,
#[strum(to_string = "P_w", serialize = "Pw")]
Pw,
#[strum(to_string = "R", serialize = "RH", serialize = "RelHum")]
R,
#[strum(to_string = "S", serialize = "Sda", serialize = "S_da", serialize = "Entropy")]
Sda,
#[strum(to_string = "Sha", serialize = "S_ha")]
Sha,
#[strum(to_string = "T", serialize = "Tdb", serialize = "T_db", serialize = "Temperature")]
T,
#[strum(to_string = "V", serialize = "Vda", serialize = "V_da")]
Vda,
#[strum(to_string = "Vha", serialize = "V_ha")]
Vha,
#[strum(to_string = "W", serialize = "Omega", serialize = "HumRat")]
W,
#[strum(to_string = "Z", serialize = "Compressibility")]
Z,
}
#[cfg(test)]
mod tests {
use std::str::FromStr;
use rstest::*;
use super::{HumidAirParam::*, *};
#[rstest]
#[case(TWetBulb, "B")]
#[case(Cpda, "C")]
#[case(Cpha, "Cha")]
#[case(Cvda, "CV")]
#[case(Cvha, "CVha")]
#[case(TDew, "D")]
#[case(Hda, "H")]
#[case(Hha, "Hha")]
#[case(Conductivity, "K")]
#[case(DynamicViscosity, "M")]
#[case(PsiW, "psi_w")]
#[case(P, "P")]
#[case(Pw, "P_w")]
#[case(R, "R")]
#[case(Sda, "S")]
#[case(Sha, "Sha")]
#[case(T, "T")]
#[case(Vda, "V")]
#[case(Vha, "Vha")]
#[case(W, "W")]
#[case(Z, "Z")]
fn as_str(#[case] sut: HumidAirParam, #[case] expected: &str) {
let str = sut.as_ref();
let static_str: &'static str = sut.into();
assert_eq!(str, expected);
assert_eq!(static_str, expected);
}
#[rstest]
#[case(vec!["B", "Twb", "T_wb", "WetBulb", "TWetBulb"], TWetBulb)]
#[case(vec!["C", "Cp", "Cpda", "Cp_da"], Cpda)]
#[case(vec!["Cha", "Cpha", "Cp_ha"], Cpha)]
#[case(vec!["CV", "Cvda", "Cv_da"], Cvda)]
#[case(vec!["CVha", "Cv_ha"], Cvha)]
#[case(vec!["D", "Tdp", "T_dp", "DewPoint", "TDew"], TDew)]
#[case(vec!["H", "Hda", "H_da", "Enthalpy"], Hda)]
#[case(vec!["Hha", "H_ha"], Hha)]
#[case(vec!["K", "Conductivity"], Conductivity)]
#[case(vec!["M", "Visc", "mu", "viscosity", "DynamicViscosity"], DynamicViscosity)]
#[case(vec!["psi_w", "Y", "PsiW"], PsiW)]
#[case(vec!["P", "Pressure"], P)]
#[case(vec!["P_w", "Pw"], Pw)]
#[case(vec!["R", "RH", "RelHum"], R)]
#[case(vec!["S", "Sda", "S_da", "Entropy"], Sda)]
#[case(vec!["Sha", "S_ha"], Sha)]
#[case(vec!["T", "Tdb", "T_db", "Temperature"], T)]
#[case(vec!["V", "Vda", "V_da"], Vda)]
#[case(vec!["Vha", "V_ha"], Vha)]
#[case(vec!["W", "Omega", "HumRat"], W)]
#[case(vec!["Z", "Compressibility"], Z)]
fn from_valid_str(#[case] valid: Vec<&str>, #[case] expected: HumidAirParam) {
for s in valid {
let res1 = HumidAirParam::from_str(s).unwrap();
let res2 = HumidAirParam::try_from(s).unwrap();
assert_eq!(res1, expected);
assert_eq!(res2, expected);
}
}
#[rstest]
#[case("")]
#[case("Hello, World!")]
fn from_invalid_str(#[case] invalid: &str) {
let res1 = HumidAirParam::from_str(invalid);
let res2 = HumidAirParam::try_from(invalid);
assert!(res1.is_err());
assert!(res2.is_err());
}
}