rootfinder/utils/
enums.rs1#[derive(Debug)]
3pub enum SolverError {
4 BracketingIntervalNotFound,
6
7 IntervalDoesNotBracketSignChange,
9}
10
11impl std::fmt::Display for SolverError {
12 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
13 match self {
14 SolverError::BracketingIntervalNotFound => {
15 write!(
16 f,
17 "No interval was found that brackets a sign change of the function."
18 )
19 }
20 SolverError::IntervalDoesNotBracketSignChange => {
21 write!(
22 f,
23 "The provided interval does not bracket a sign change of the function."
24 )
25 }
26 }
27 }
28}
29
30#[derive(Debug, Default, PartialEq)]
36pub enum TerminationReason {
37 #[default]
39 NotYetTerminated,
40
41 MaxIterationsReached,
43
44 MaxFunctionEvaluationsReached,
46
47 AbsoluteBracketToleranceSatisfied,
49
50 RelativeBracketToleranceSatisfied,
52
53 AbsoluteStepToleranceSatisfied,
55
56 ValueToleranceSatisfied,
58
59 ZeroDerivative,
65
66 RootAtLowerBound,
68
69 RootAtUpperBound,
71}
72
73#[cfg(test)]
74mod tests {
75 use super::*;
76
77 #[test]
78 fn test_solver_error_bracketing_interval_not_found() {
79 assert_eq!(
80 format!("{}", SolverError::BracketingIntervalNotFound),
81 "No interval was found that brackets a sign change of the function."
82 );
83 assert_eq!(
84 format!("{}", SolverError::IntervalDoesNotBracketSignChange),
85 "The provided interval does not bracket a sign change of the function."
86 );
87 }
88
89 #[test]
90 fn test_termination_reason_default() {
91 let termination_reason = TerminationReason::default();
92 assert!(matches!(
93 termination_reason,
94 TerminationReason::NotYetTerminated
95 ));
96 }
97}