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

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

impl CompareSubBranchOrdering for GrowerTreeConfiguration {
    fn compare_sub_branch_ordering(&self, other: &GrowerTreeConfiguration) -> CompareOutcome {
        match (self.ordering(), other.ordering()) {
            (None, None) => CompareOutcome::Exact,
            (None, Some(_)) | (Some(_), None) => CompareOutcome::Partial(0.5),
            (Some(a), Some(b)) => {
                if a == b {
                    CompareOutcome::Exact
                } else {
                    CompareOutcome::Partial(0.3)
                }
            }
        }
    }
}

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

    #[traced_test]
    fn both_none() {
        let a = GrowerTreeConfiguration::default();
        let b = GrowerTreeConfiguration::default();
        assert_eq!(a.compare_sub_branch_ordering(&b), CompareOutcome::Exact);
    }

    #[traced_test]
    fn same_variant() {
        let a = GrowerTreeConfiguration::default()
            .to_builder().ordering(Some(SubBranchOrdering::Alphabetical)).build().unwrap();
        let b = a.clone();
        assert_eq!(a.compare_sub_branch_ordering(&b), CompareOutcome::Exact);
    }

    #[traced_test]
    fn different_variant_partial() {
        let a = GrowerTreeConfiguration::default()
            .to_builder().ordering(Some(SubBranchOrdering::Random)).build().unwrap();
        let b = a.to_builder().ordering(Some(SubBranchOrdering::DifficultyDescending)).build().unwrap();
        let out = a.compare_sub_branch_ordering(&b);
        match out {
            CompareOutcome::Partial(_) => {},
            other => panic!("expected partial, got {:?}", other),
        }
    }

    #[traced_test]
    fn one_none_one_some_partial() {
        let a = GrowerTreeConfiguration::default();
        let b = a.to_builder().ordering(Some(SubBranchOrdering::Chronological)).build().unwrap();
        match a.compare_sub_branch_ordering(&b) {
            CompareOutcome::Partial(_) => {},
            other => panic!("expected partial, got {:?}", other),
        }
    }
}