capability-grower-configuration-comparison 0.1.0

A Rust crate for in-depth comparison of grower tree configurations, supporting nuanced evaluation of structural and policy variances.
Documentation
// ---------------- [ File: capability-grower-configuration-comparison/src/compare_allow_early_leaves.rs ]
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 {
            // for demonstration, let's say that's partial
            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),
        }
    }
}