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_depth.rs ]
crate::ix!();

pub trait CompareDepth {
    fn compare_depth(&self, other: &GrowerTreeConfiguration) -> CompareOutcome;
}

impl CompareDepth for GrowerTreeConfiguration {
    fn compare_depth(&self, other: &GrowerTreeConfiguration) -> CompareOutcome {
        let d1 = self.depth();
        let d2 = other.depth();
        if d1 == d2 {
            CompareOutcome::Exact
        } else {
            let diff = (*d1 as i32 - *d2 as i32).abs();
            // E.g. big difference => Incompatible, smaller => partial
            if diff > 3 {
                CompareOutcome::Incompatible
            } else {
                // partial with some decreasing score
                let penalty = 0.2 * diff as f32;
                let score = (1.0 - penalty).max(0.0);
                CompareOutcome::Partial(score)
            }
        }
    }
}

#[cfg(test)]
mod compare_depth_tests {
    use super::*;
    use traced_test::traced_test;

    #[traced_test]
    fn same_depth_returns_exact() {
        let a = GrowerTreeConfiguration::base_config(5, 2, 2);
        let b = GrowerTreeConfiguration::base_config(5, 3, 2);
        let outcome = a.compare_depth(&b);
        assert_eq!(outcome, CompareOutcome::Exact);
    }

    #[traced_test]
    fn difference_small_returns_partial() {
        let a = GrowerTreeConfiguration::base_config(5, 2, 2);
        let b = GrowerTreeConfiguration::base_config(6, 2, 2); // diff=1 => partial
        let outcome = a.compare_depth(&b);
        assert!(matches!(outcome, CompareOutcome::Partial(_)));

        let c = GrowerTreeConfiguration::base_config(7, 2, 2); // diff=2 => partial
        let o2 = a.compare_depth(&c);
        assert!(matches!(o2, CompareOutcome::Partial(_)));
    }

    #[traced_test]
    fn difference_large_returns_incompatible() {
        let a = GrowerTreeConfiguration::base_config(5, 2, 2);
        let b = GrowerTreeConfiguration::base_config(9, 2, 2); // diff=4 => incompatible
        let outcome = a.compare_depth(&b);
        assert_eq!(outcome, CompareOutcome::Incompatible);
    }
}