#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum OtherConstant {
True,
False,
Nothing,
Pi,
Nan,
Ind,
Inf,
}
impl OtherConstant {
pub const ALL: [Self; 7] = [
Self::True,
Self::False,
Self::Nothing,
Self::Pi,
Self::Nan,
Self::Ind,
Self::Inf,
];
#[must_use]
pub const fn name(self) -> &'static str {
match self {
Self::True => "True",
Self::False => "False",
Self::Nothing => "Nothing",
Self::Pi => "PI",
Self::Nan => "NAN",
Self::Ind => "IND",
Self::Inf => "INF",
}
}
#[must_use]
pub const fn is_non_finite(self) -> bool {
matches!(self, Self::Nan | Self::Ind | Self::Inf)
}
}
#[cfg(test)]
mod tests {
use super::OtherConstant;
#[test]
fn every_name_is_distinct() {
let mut names: Vec<&str> = OtherConstant::ALL.iter().map(|item| item.name()).collect();
names.sort_unstable();
let count = names.len();
names.dedup();
assert_eq!(names.len(), count);
}
#[test]
fn the_non_finite_constants_are_grouped() {
for constant in [OtherConstant::Nan, OtherConstant::Ind, OtherConstant::Inf] {
assert!(constant.is_non_finite(), "{constant:?}");
}
assert!(!OtherConstant::Pi.is_non_finite());
}
}