mod base;
mod default;
mod tabular;
use std::borrow::Cow;
pub use base::*;
pub use default::*;
pub use tabular::*;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum Backend {
Base(BaseBackend),
Tabular {
base: BaseBackend,
method: TabularMethod,
},
}
impl Backend {
#[must_use]
pub fn name(&self) -> Cow<'static, str> {
match self {
Backend::Base(base) => Cow::Borrowed(base.into()),
Backend::Tabular { method, base } => {
Cow::Owned(format!("{}&{}", method.as_ref(), base.as_ref()))
}
}
}
}
impl From<BaseBackend> for Backend {
fn from(value: BaseBackend) -> Self {
Self::Base(value)
}
}
#[cfg(test)]
mod tests {
use rstest::*;
use super::{BaseBackend::*, TabularMethod::*, *};
#[rstest]
#[case(Heos, "HEOS", false)]
#[case(Refprop, "REFPROP", false)]
#[case(Incomp, "INCOMP", false)]
#[case(If97, "IF97", false)]
#[case(Srk, "SRK", false)]
#[case(Pr, "PR", false)]
#[case(VtPr, "VTPR", false)]
#[case(PcSaft, "PCSAFT", false)]
#[case(Heos.with(Ttse), "TTSE&HEOS", true)]
#[case(Refprop.with(Ttse), "TTSE&REFPROP", true)]
#[case(Incomp.with(Ttse), "TTSE&INCOMP", true)]
#[case(If97.with(Ttse), "TTSE&IF97", true)]
#[case(Srk.with(Ttse), "TTSE&SRK", true)]
#[case(Pr.with(Ttse), "TTSE&PR", true)]
#[case(VtPr.with(Ttse), "TTSE&VTPR", true)]
#[case(PcSaft.with(Ttse), "TTSE&PCSAFT", true)]
#[case(Heos.with(Bicubic), "BICUBIC&HEOS", true)]
#[case(Refprop.with(Bicubic), "BICUBIC&REFPROP", true)]
#[case(Incomp.with(Bicubic), "BICUBIC&INCOMP", true)]
#[case(If97.with(Bicubic), "BICUBIC&IF97", true)]
#[case(Srk.with(Bicubic), "BICUBIC&SRK", true)]
#[case(Pr.with(Bicubic), "BICUBIC&PR", true)]
#[case(VtPr.with(Bicubic), "BICUBIC&VTPR", true)]
#[case(PcSaft.with(Bicubic), "BICUBIC&PCSAFT", true)]
fn name(#[case] sut: impl Into<Backend>, #[case] expected: &str, #[case] is_owned: bool) {
let sut = sut.into();
let res = sut.name();
assert_eq!(res, expected);
assert_eq!(matches!(res, Cow::Owned(_)), is_owned);
}
}