parametrizer/term/
constantterm.rs

1use crate::Number;
2use super::Term;
3
4/// A Term that returns a constant value no matter what value is passed in
5pub struct ConstantTerm<T: Number>
6{
7
8    c: T
9
10}
11
12impl<T:Number> ConstantTerm<T>
13{
14
15    ///Creates a ConstantTerm obtained by parsing a string slice
16    ///
17    /// # Examples
18    ///
19    /// ```
20    /// use crate::parametrizer::term::constantterm::ConstantTerm;
21    /// use crate::parametrizer::term::Term;
22    ///
23    /// let int_constant = ConstantTerm::new(17);
24    /// let float_constant = ConstantTerm::new(5.2);
25    ///
26    /// assert_eq!(17, int_constant.evaluate(9));
27    /// assert_eq!(17, int_constant.evaluate(-1));
28    /// assert_eq!(5.2, float_constant.evaluate(3.4));
29    /// assert_eq!(5.2, float_constant.evaluate(5.0));
30    /// ```
31    pub fn new(param: T) -> ConstantTerm<T>
32    {
33
34        return ConstantTerm::<T> { c: param };
35
36    }
37
38}
39
40impl<T: Number> Term<T> for ConstantTerm<T>
41{
42
43    ///Returns the associated constant number no matter what value of t is passed in
44    fn evaluate(&self, _t: T) -> T
45    {
46
47        return self.c;
48
49    }
50
51}