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

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

impl CompareBreadth for GrowerTreeConfiguration {
    fn compare_breadth(&self, other: &GrowerTreeConfiguration) -> CompareOutcome {
        let b1 = *self.breadth();
        let b2 = *other.breadth();
        if b1 == b2 {
            CompareOutcome::Exact
        } else {
            let diff = (b1 as i32 - b2 as i32).abs();
            if diff > 5 {
                CompareOutcome::Incompatible
            } else {
                let penalty = 0.1 * diff as f32;
                let score = (1.0 - penalty).max(0.0);
                CompareOutcome::Partial(score)
            }
        }
    }
}

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

    #[traced_test]
    fn same_breadth_exact() {
        let a = GrowerTreeConfiguration::base_config(5, 3, 2);
        let b = GrowerTreeConfiguration::base_config(6, 3, 1);
        assert_eq!(a.compare_breadth(&b), CompareOutcome::Exact);
    }

    #[traced_test]
    fn ratio_small_partial() {
        let a = GrowerTreeConfiguration::base_config(5, 4, 2);
        let b = GrowerTreeConfiguration::base_config(5, 5, 2);
        let out = a.compare_breadth(&b);
        match out {
            CompareOutcome::Partial(_) => {},
            other => panic!("Expected partial, got {:?}", other),
        }
    }

    #[traced_test]
    fn large_difference_incompatible() {
        let a = GrowerTreeConfiguration::base_config(5, 2, 2);
        let b = GrowerTreeConfiguration::base_config(5, 10, 2);
        assert_eq!(a.compare_breadth(&b), CompareOutcome::Incompatible);
    }
}