capability_grower_configuration_comparison/
compare_breadth.rs1crate::ix!();
3
4pub trait CompareBreadth {
5 fn compare_breadth(&self, other: &GrowerTreeConfiguration) -> CompareOutcome;
6}
7
8impl CompareBreadth for GrowerTreeConfiguration {
9 fn compare_breadth(&self, other: &GrowerTreeConfiguration) -> CompareOutcome {
10 let b1 = *self.breadth();
11 let b2 = *other.breadth();
12 if b1 == b2 {
13 CompareOutcome::Exact
14 } else {
15 let diff = (b1 as i32 - b2 as i32).abs();
16 if diff > 5 {
17 CompareOutcome::Incompatible
18 } else {
19 let penalty = 0.1 * diff as f32;
20 let score = (1.0 - penalty).max(0.0);
21 CompareOutcome::Partial(score)
22 }
23 }
24 }
25}
26
27#[cfg(test)]
28mod compare_breadth_tests {
29 use super::*;
30 use traced_test::traced_test;
31
32 #[traced_test]
33 fn same_breadth_exact() {
34 let a = GrowerTreeConfiguration::base_config(5, 3, 2);
35 let b = GrowerTreeConfiguration::base_config(6, 3, 1);
36 assert_eq!(a.compare_breadth(&b), CompareOutcome::Exact);
37 }
38
39 #[traced_test]
40 fn ratio_small_partial() {
41 let a = GrowerTreeConfiguration::base_config(5, 4, 2);
42 let b = GrowerTreeConfiguration::base_config(5, 5, 2);
43 let out = a.compare_breadth(&b);
44 match out {
45 CompareOutcome::Partial(_) => {},
46 other => panic!("Expected partial, got {:?}", other),
47 }
48 }
49
50 #[traced_test]
51 fn large_difference_incompatible() {
52 let a = GrowerTreeConfiguration::base_config(5, 2, 2);
53 let b = GrowerTreeConfiguration::base_config(5, 10, 2);
54 assert_eq!(a.compare_breadth(&b), CompareOutcome::Incompatible);
55 }
56}