capability_grower_configuration_comparison/
compare_allow_early_leaves.rs

1// ---------------- [ File: capability-grower-configuration-comparison/src/compare_allow_early_leaves.rs ]
2crate::ix!();
3
4pub trait CompareAllowEarlyLeaves {
5    fn compare_allow_early_leaves(&self, other: &GrowerTreeConfiguration) -> CompareOutcome;
6}
7
8impl CompareAllowEarlyLeaves for GrowerTreeConfiguration {
9    fn compare_allow_early_leaves(&self, other: &GrowerTreeConfiguration) -> CompareOutcome {
10        if self.allow_early_leaves() == other.allow_early_leaves() {
11            CompareOutcome::Exact
12        } else {
13            // for demonstration, let's say that's partial
14            CompareOutcome::Partial(0.5)
15        }
16    }
17}
18
19#[cfg(test)]
20mod compare_allow_early_leaves_tests {
21    use super::*;
22
23    #[traced_test]
24    fn both_same_exact() {
25        let a = GrowerTreeConfiguration::default()
26            .to_builder().allow_early_leaves(true).build().unwrap();
27        let b = a.clone();
28        assert_eq!(a.compare_allow_early_leaves(&b), CompareOutcome::Exact);
29    }
30
31    #[traced_test]
32    fn different_partial() {
33        let a = GrowerTreeConfiguration::default()
34            .to_builder().allow_early_leaves(false).build().unwrap();
35        let b = a.to_builder().allow_early_leaves(true).build().unwrap();
36        match a.compare_allow_early_leaves(&b) {
37            CompareOutcome::Partial(_) => {},
38            other => panic!("expected partial, got {:?}", other),
39        }
40    }
41}