use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum RidgePolicy {
ExactFullObjective,
SolverOnly,
}
impl RidgePolicy {
pub const fn exact_full_objective() -> Self {
Self::ExactFullObjective
}
pub const fn solver_only() -> Self {
Self::SolverOnly
}
#[inline]
pub const fn accounts_for_objective(self) -> bool {
!matches!(self, Self::SolverOnly)
}
}
#[cfg(test)]
mod ridge_policy_tests {
use super::*;
#[test]
fn exact_policy_accounts_for_the_objective() {
assert!(RidgePolicy::exact_full_objective().accounts_for_objective());
}
#[test]
fn solver_only_policy_cannot_enter_objective_accounting() {
assert!(!RidgePolicy::solver_only().accounts_for_objective());
}
#[test]
fn the_policy_has_no_third_inhabitant() {
let constructed = [
RidgePolicy::exact_full_objective(),
RidgePolicy::solver_only(),
];
let mut exact = 0usize;
let mut solver = 0usize;
for policy in constructed {
let (RidgePolicy::ExactFullObjective | RidgePolicy::SolverOnly) = policy;
match policy {
RidgePolicy::ExactFullObjective => exact += 1,
RidgePolicy::SolverOnly => solver += 1,
}
}
assert_eq!(
(exact, solver),
(1, 1),
"the two constructors must reach the two distinct inhabitants, once each"
);
assert_ne!(
constructed[0], constructed[1],
"a constructor re-pointed at its sibling leaves the enum's arity intact \
and the engine with one selectable policy"
);
}
}