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

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

impl CompareAggregatorPreference for GrowerTreeConfiguration {
    fn compare_aggregator_preference(&self, other: &GrowerTreeConfiguration) -> CompareOutcome {
        let diff = (self.aggregator_preference() - other.aggregator_preference()).abs();
        if diff < 0.01 {
            CompareOutcome::Exact
        } else if diff < 0.2 {
            CompareOutcome::Partial(1.0 - diff)
        } else {
            CompareOutcome::Incompatible
        }
    }
}

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

    #[traced_test]
    fn exact_match() {
        let a = GrowerTreeConfiguration::default()
            .to_builder().aggregator_preference(0.5).build().unwrap();
        let b = a.clone();
        assert_eq!(a.compare_aggregator_preference(&b), CompareOutcome::Exact);
    }

    #[traced_test]
    fn partial() {
        let a = GrowerTreeConfiguration::default()
            .to_builder().aggregator_preference(0.3).build().unwrap();
        let b = a.to_builder().aggregator_preference(0.4).build().unwrap();
        match a.compare_aggregator_preference(&b) {
            CompareOutcome::Partial(_) => {}
            other => panic!("Expected partial, got {:?}", other),
        }
    }

    #[traced_test]
    fn incompatible() {
        let a = GrowerTreeConfiguration::default()
            .to_builder().aggregator_preference(0.0).build().unwrap();
        let b = a.to_builder().aggregator_preference(1.0).build().unwrap();
        assert_eq!(a.compare_aggregator_preference(&b), CompareOutcome::Incompatible);
    }
}