crate::ix!();
pub trait CompareComplexity {
fn compare_complexity(&self, other: &GrowerTreeConfiguration) -> CompareOutcome;
}
impl CompareComplexity for GrowerTreeConfiguration {
fn compare_complexity(&self, other: &GrowerTreeConfiguration) -> CompareOutcome {
if self.complexity() == other.complexity() {
CompareOutcome::Exact
} else {
CompareOutcome::Partial(0.5)
}
}
}
#[cfg(test)]
mod compare_complexity_tests {
use super::*;
#[traced_test]
fn exact() {
let a = GrowerTreeConfiguration::base_config(5,2,2)
.to_builder().complexity(ConfigurationComplexity::Balanced).build().unwrap();
let b = a.clone();
assert_eq!(a.compare_complexity(&b), CompareOutcome::Exact);
}
#[traced_test]
fn partial_example() {
let a = GrowerTreeConfiguration::base_config(5,2,2)
.to_builder().complexity(ConfigurationComplexity::Balanced).build().unwrap();
let b = a.to_builder().complexity(ConfigurationComplexity::Simple).build().unwrap();
match a.compare_complexity(&b) {
CompareOutcome::Partial(0.5) => {},
other => panic!("Expected partial(0.5), got {:?}", other),
}
}
#[traced_test]
fn one_more_variant_example() {
let a = GrowerTreeConfiguration::base_config(5,2,2)
.to_builder().complexity(ConfigurationComplexity::Simple).build().unwrap();
let b = a.to_builder().complexity(ConfigurationComplexity::Complex).build().unwrap();
match a.compare_complexity(&b) {
CompareOutcome::Partial(_) => {},
other => panic!("expected partial, got {:?}", other),
}
}
}