#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_complexity_bound_size() {
let size = std::mem::size_of::<ComplexityBound>();
assert!(
size == 8 || size == 16,
"ComplexityBound size is {size} bytes"
);
assert_eq!(std::mem::align_of::<ComplexityBound>(), 8);
}
#[test]
fn test_cache_complexity_size() {
assert_eq!(std::mem::size_of::<CacheComplexity>(), 8);
assert_eq!(std::mem::align_of::<CacheComplexity>(), 8);
}
#[test]
fn test_big_o_ordering() {
assert!(BigOClass::Constant.is_better_than(&BigOClass::Linear));
assert!(BigOClass::Linear.is_better_than(&BigOClass::Quadratic));
assert!(BigOClass::Logarithmic.is_better_than(&BigOClass::Linear));
assert!(BigOClass::Linearithmic.is_better_than(&BigOClass::Quadratic));
}
#[test]
fn test_complexity_bound_creation() {
let bound = ComplexityBound::linear()
.with_confidence(90)
.with_flags(ComplexityFlags::PROVEN | ComplexityFlags::TIGHT_BOUND);
assert_eq!(bound.class, BigOClass::Linear);
assert_eq!(bound.confidence, 90);
assert!(bound.flags.is_proven());
assert_eq!(bound.notation(), "O(n)");
}
#[test]
fn test_growth_estimation() {
let linear = ComplexityBound::linear();
let quadratic = ComplexityBound::quadratic();
assert_eq!(linear.estimate_operations(100.0), 100.0);
assert_eq!(quadratic.estimate_operations(100.0), 10000.0);
}
#[test]
fn test_master_theorem() {
let recurrence = RecurrenceRelation {
recursive_calls: vec![RecursiveCall {
division_factor: 2,
size_reduction: 0,
count: 2,
}],
work_per_call: ComplexityBound::linear(),
base_case_size: 1,
};
let solution = recurrence.solve_master_theorem();
assert!(solution.is_some());
assert_eq!(solution.unwrap().class, BigOClass::Linearithmic);
}
}
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod property_tests {
use proptest::prelude::*;
proptest! {
#[test]
fn basic_property_stability(_input in ".*") {
prop_assert!(true);
}
#[test]
fn module_consistency_check(_x in 0u32..1000) {
prop_assert!(_x < 1001);
}
}
}