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

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

impl ComparePartialSubbranchProbability for GrowerTreeConfiguration {
    fn compare_partial_subbranch_probability(&self, other: &GrowerTreeConfiguration) -> CompareOutcome {
        let diff = (self.partial_subbranch_probability() - other.partial_subbranch_probability()).abs();
        if diff < 0.01 {
            CompareOutcome::Exact
        } else if diff < 0.3 {
            CompareOutcome::Partial(1.0 - diff)
        } else {
            CompareOutcome::Incompatible
        }
    }
}

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

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

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

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