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

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

impl CompareComplexity for GrowerTreeConfiguration {
    fn compare_complexity(&self, other: &GrowerTreeConfiguration) -> CompareOutcome {
        if self.complexity() == other.complexity() {
            CompareOutcome::Exact
        } else {
            // example: partial if they differ
            CompareOutcome::Partial(0.5)
        }
    }
}

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

    #[traced_test]
    fn exact() {
        let a = GrowerTreeConfiguration::base_config(5,2,2)
            .to_builder().complexity(ConfigurationComplexity::Balanced).build().unwrap();
        let b = a.clone();
        assert_eq!(a.compare_complexity(&b), CompareOutcome::Exact);
    }

    #[traced_test]
    fn partial_example() {
        let a = GrowerTreeConfiguration::base_config(5,2,2)
            .to_builder().complexity(ConfigurationComplexity::Balanced).build().unwrap();
        let b = a.to_builder().complexity(ConfigurationComplexity::Simple).build().unwrap();
        match a.compare_complexity(&b) {
            CompareOutcome::Partial(0.5) => {},
            other => panic!("Expected partial(0.5), got {:?}", other),
        }
    }

    #[traced_test]
    fn one_more_variant_example() {
        let a = GrowerTreeConfiguration::base_config(5,2,2)
            .to_builder().complexity(ConfigurationComplexity::Simple).build().unwrap();
        let b = a.to_builder().complexity(ConfigurationComplexity::Complex).build().unwrap();
        // we said "just partial(0.5)" in the logic above, but you might want Incompatible.
        match a.compare_complexity(&b) {
            CompareOutcome::Partial(_) => {},
            other => panic!("expected partial, got {:?}", other),
        }
    }
}