Skip to main content

rs_teststand/expression/function/
numeric.rs

1//! Numeric expression functions.
2
3/// A numeric function of the expression language.
4///
5/// Names only: what each one computes is the engine's to document.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum NumericFunction {
8    /// `Abs`.
9    Abs,
10    /// `ACos`.
11    ACos,
12    /// `Asc`.
13    Asc,
14    /// `ASin`.
15    ASin,
16    /// `ATan`.
17    ATan,
18    /// `Cos`.
19    Cos,
20    /// `Exp`.
21    Exp,
22    /// `Float64`.
23    Float64,
24    /// `Int64`.
25    Int64,
26    /// `Log`.
27    Log,
28    /// `Log10`.
29    Log10,
30    /// `Max`.
31    Max,
32    /// `Min`.
33    Min,
34    /// `Pow`.
35    Pow,
36    /// `Random`.
37    Random,
38    /// `Round`.
39    Round,
40    /// `Sin`.
41    Sin,
42    /// `Sqrt`.
43    Sqrt,
44    /// `Tan`.
45    Tan,
46    /// `UInt64`.
47    UInt64,
48    /// `Val`.
49    Val,
50}
51
52impl NumericFunction {
53    /// Every function in this family.
54    pub const ALL: [Self; 21] = [
55        Self::Abs,
56        Self::ACos,
57        Self::Asc,
58        Self::ASin,
59        Self::ATan,
60        Self::Cos,
61        Self::Exp,
62        Self::Float64,
63        Self::Int64,
64        Self::Log,
65        Self::Log10,
66        Self::Max,
67        Self::Min,
68        Self::Pow,
69        Self::Random,
70        Self::Round,
71        Self::Sin,
72        Self::Sqrt,
73        Self::Tan,
74        Self::UInt64,
75        Self::Val,
76    ];
77
78    /// The name as written in an expression.
79    #[must_use]
80    pub const fn name(self) -> &'static str {
81        match self {
82            Self::Abs => "Abs",
83            Self::ACos => "ACos",
84            Self::Asc => "Asc",
85            Self::ASin => "ASin",
86            Self::ATan => "ATan",
87            Self::Cos => "Cos",
88            Self::Exp => "Exp",
89            Self::Float64 => "Float64",
90            Self::Int64 => "Int64",
91            Self::Log => "Log",
92            Self::Log10 => "Log10",
93            Self::Max => "Max",
94            Self::Min => "Min",
95            Self::Pow => "Pow",
96            Self::Random => "Random",
97            Self::Round => "Round",
98            Self::Sin => "Sin",
99            Self::Sqrt => "Sqrt",
100            Self::Tan => "Tan",
101            Self::UInt64 => "UInt64",
102            Self::Val => "Val",
103        }
104    }
105}
106
107#[cfg(test)]
108mod tests {
109    use super::NumericFunction;
110
111    #[test]
112    fn every_name_is_distinct() {
113        let mut names: Vec<&str> = NumericFunction::ALL.iter().map(|f| f.name()).collect();
114        names.sort_unstable();
115        let count = names.len();
116        names.dedup();
117        assert_eq!(names.len(), count);
118    }
119}