crate::ix!();
pub trait CompareAllowEarlyLeaves {
fn compare_allow_early_leaves(&self, other: &GrowerTreeConfiguration) -> CompareOutcome;
}
impl CompareAllowEarlyLeaves for GrowerTreeConfiguration {
fn compare_allow_early_leaves(&self, other: &GrowerTreeConfiguration) -> CompareOutcome {
if self.allow_early_leaves() == other.allow_early_leaves() {
CompareOutcome::Exact
} else {
CompareOutcome::Partial(0.5)
}
}
}
#[cfg(test)]
mod compare_allow_early_leaves_tests {
use super::*;
#[traced_test]
fn both_same_exact() {
let a = GrowerTreeConfiguration::default()
.to_builder().allow_early_leaves(true).build().unwrap();
let b = a.clone();
assert_eq!(a.compare_allow_early_leaves(&b), CompareOutcome::Exact);
}
#[traced_test]
fn different_partial() {
let a = GrowerTreeConfiguration::default()
.to_builder().allow_early_leaves(false).build().unwrap();
let b = a.to_builder().allow_early_leaves(true).build().unwrap();
match a.compare_allow_early_leaves(&b) {
CompareOutcome::Partial(_) => {},
other => panic!("expected partial, got {:?}", other),
}
}
}