#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_format_bytes() {
assert_eq!(format_bytes(0), "0 B");
assert_eq!(format_bytes(1023), "1023 B");
assert_eq!(format_bytes(1024), "1.0 KB");
assert_eq!(format_bytes(1536), "1.5 KB");
assert_eq!(format_bytes(1048576), "1.0 MB");
assert_eq!(format_bytes(1073741824), "1.0 GB");
}
#[test]
fn test_memory_stats_output_serialization() -> Result<()> {
let mut pool_stats = HashMap::new();
pool_stats.insert(
"TestPool".to_string(),
PoolStatsOutput {
buffer_count: 5,
total_size: 1024,
allocation_count: 10,
reuse_count: 8,
reuse_ratio: 0.8,
efficiency_rating: "Good".to_string(),
},
);
let stats = MemoryStatsOutput {
total_allocated: 2048,
peak_usage: 3072,
allocation_pressure: 0.5,
string_intern_size: 512,
pool_stats,
recommendations: vec!["All good".to_string()],
};
let json = serde_json::to_string(&stats)?;
assert!(json.contains("total_allocated"));
assert!(json.contains("2048"));
Ok(())
}
}
#[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);
}
}
}