capability_grower_configuration_comparison/
compare_complexity.rs1crate::ix!();
3
4pub trait CompareComplexity {
5 fn compare_complexity(&self, other: &GrowerTreeConfiguration) -> CompareOutcome;
6}
7
8impl CompareComplexity for GrowerTreeConfiguration {
9 fn compare_complexity(&self, other: &GrowerTreeConfiguration) -> CompareOutcome {
10 if self.complexity() == other.complexity() {
11 CompareOutcome::Exact
12 } else {
13 CompareOutcome::Partial(0.5)
15 }
16 }
17}
18
19#[cfg(test)]
20mod compare_complexity_tests {
21 use super::*;
22
23 #[traced_test]
24 fn exact() {
25 let a = GrowerTreeConfiguration::base_config(5,2,2)
26 .to_builder().complexity(ConfigurationComplexity::Balanced).build().unwrap();
27 let b = a.clone();
28 assert_eq!(a.compare_complexity(&b), CompareOutcome::Exact);
29 }
30
31 #[traced_test]
32 fn partial_example() {
33 let a = GrowerTreeConfiguration::base_config(5,2,2)
34 .to_builder().complexity(ConfigurationComplexity::Balanced).build().unwrap();
35 let b = a.to_builder().complexity(ConfigurationComplexity::Simple).build().unwrap();
36 match a.compare_complexity(&b) {
37 CompareOutcome::Partial(0.5) => {},
38 other => panic!("Expected partial(0.5), got {:?}", other),
39 }
40 }
41
42 #[traced_test]
43 fn one_more_variant_example() {
44 let a = GrowerTreeConfiguration::base_config(5,2,2)
45 .to_builder().complexity(ConfigurationComplexity::Simple).build().unwrap();
46 let b = a.to_builder().complexity(ConfigurationComplexity::Complex).build().unwrap();
47 match a.compare_complexity(&b) {
49 CompareOutcome::Partial(_) => {},
50 other => panic!("expected partial, got {:?}", other),
51 }
52 }
53}