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

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

impl CompareBalanceSymmetry for GrowerTreeConfiguration {
    fn compare_balance_symmetry(&self, other: &GrowerTreeConfiguration) -> CompareOutcome {
        let b1 = self.balance_symmetry();
        let b2 = other.balance_symmetry();
        let diff = (b1 - b2).abs();
        if diff < 0.01 {
            CompareOutcome::Exact
        } else if diff < 0.2 {
            let score = 1.0 - diff * 2.0;
            CompareOutcome::Partial(score.max(0.0))
        } else {
            CompareOutcome::Incompatible
        }
    }
}

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

    #[traced_test]
    fn exact_match() {
        let a = GrowerTreeConfiguration::base_config(5,3,2)
            .to_builder().balance_symmetry(0.6).build().unwrap();
        let b = a.clone();
        assert_eq!(a.compare_balance_symmetry(&b), CompareOutcome::Exact);
    }

    #[traced_test]
    fn partial_match() {
        let a = GrowerTreeConfiguration::base_config(5,3,2)
            .to_builder().balance_symmetry(0.7).build().unwrap();
        let b = a.to_builder().balance_symmetry(0.5).build().unwrap();
        match a.compare_balance_symmetry(&b) {
            CompareOutcome::Partial(_) => {},
            other => panic!("expected partial, got {:?}", other),
        }
    }

    #[traced_test]
    fn incompatible() {
        let a = GrowerTreeConfiguration::base_config(5,3,2)
            .to_builder().balance_symmetry(0.1).build().unwrap();
        let b = a.to_builder().balance_symmetry(0.9).build().unwrap();
        assert_eq!(a.compare_balance_symmetry(&b), CompareOutcome::Incompatible);
    }
}