#[derive(Debug)]
pub enum SolverError {
BracketingIntervalNotFound,
IntervalDoesNotBracketSignChange,
}
impl std::fmt::Display for SolverError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
SolverError::BracketingIntervalNotFound => {
write!(
f,
"No interval was found that brackets a sign change of the function."
)
}
SolverError::IntervalDoesNotBracketSignChange => {
write!(
f,
"The provided interval does not bracket a sign change of the function."
)
}
}
}
}
#[derive(Debug, Default, PartialEq)]
pub enum TerminationReason {
#[default]
NotYetTerminated,
MaxIterationsReached,
MaxFunctionEvaluationsReached,
AbsoluteBracketToleranceSatisfied,
RelativeBracketToleranceSatisfied,
AbsoluteStepToleranceSatisfied,
ValueToleranceSatisfied,
ZeroDerivative,
RootAtLowerBound,
RootAtUpperBound,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_solver_error_bracketing_interval_not_found() {
assert_eq!(
format!("{}", SolverError::BracketingIntervalNotFound),
"No interval was found that brackets a sign change of the function."
);
assert_eq!(
format!("{}", SolverError::IntervalDoesNotBracketSignChange),
"The provided interval does not bracket a sign change of the function."
);
}
#[test]
fn test_termination_reason_default() {
let termination_reason = TerminationReason::default();
assert!(matches!(
termination_reason,
TerminationReason::NotYetTerminated
));
}
}