#[cfg(test)]
mod coverage_tests {
use super::*;
use std::sync::atomic::Ordering;
use std::time::Duration;
#[test]
fn test_cache_config_reexport() {
let config = CacheConfig::default();
assert_eq!(config.max_memory_mb, 100);
}
#[test]
fn test_cache_entry_reexport() {
let entry = CacheEntry::new("test_value".to_string(), 100);
assert_eq!(entry.size_bytes, 100);
assert_eq!(*entry.value, "test_value");
}
#[test]
fn test_cache_stats_reexport() {
let stats = CacheStats::new();
assert_eq!(stats.hits.load(Ordering::Relaxed), 0);
assert_eq!(stats.misses.load(Ordering::Relaxed), 0);
}
#[test]
fn test_cache_strategy_reexport() {
let ast_strategy = AstCacheStrategy;
assert_eq!(ast_strategy.ttl(), Some(Duration::from_secs(300)));
let template_strategy = TemplateCacheStrategy;
assert_eq!(template_strategy.ttl(), Some(Duration::from_secs(600)));
let dag_strategy = DagCacheStrategy;
assert_eq!(dag_strategy.ttl(), Some(Duration::from_secs(180)));
let churn_strategy = ChurnCacheStrategy;
assert_eq!(churn_strategy.ttl(), Some(Duration::from_secs(1800)));
let git_stats_strategy = GitStatsCacheStrategy;
assert_eq!(git_stats_strategy.ttl(), Some(Duration::from_secs(900)));
}
#[test]
fn test_git_stats_struct_creation() {
let stats = GitStats {
total_commits: 42,
authors: vec!["alice".to_string(), "bob".to_string()],
branch: "main".to_string(),
head_commit: "abc123def456".to_string(),
};
assert_eq!(stats.total_commits, 42);
assert_eq!(stats.authors.len(), 2);
assert_eq!(stats.branch, "main");
assert_eq!(stats.head_commit, "abc123def456");
}
#[test]
fn test_advanced_cache_config_reexport() {
let config = AdvancedCacheConfig::default();
let _ = config.eviction_policy;
}
#[test]
fn test_eviction_policy_reexport() {
let lru = EvictionPolicy::LRU;
let lfu = EvictionPolicy::LFU;
let adaptive = EvictionPolicy::Adaptive;
match lru {
EvictionPolicy::LRU => {}
_ => panic!("Expected LRU"),
}
match lfu {
EvictionPolicy::LFU => {}
_ => panic!("Expected LFU"),
}
match adaptive {
EvictionPolicy::Adaptive => {}
_ => panic!("Expected Adaptive"),
}
}
#[test]
fn test_cache_tier_reexport() {
let l1 = CacheTier::L1;
let l2 = CacheTier::L2;
let l3 = CacheTier::L3;
match l1 {
CacheTier::L1 => {}
_ => panic!("Expected L1"),
}
match l2 {
CacheTier::L2 => {}
_ => panic!("Expected L2"),
}
match l3 {
CacheTier::L3 => {}
_ => panic!("Expected L3"),
}
}
#[test]
fn test_orchestrator_config_reexport() {
let config = OrchestratorConfig::default();
assert!(
config.evaluation_interval.as_secs() > 0 || config.evaluation_interval.as_millis() > 0
);
}
#[test]
fn test_workload_profile_reexport() {
let profile = WorkloadProfile {
request_rate: 100.0,
working_set_size: 1024,
temporal_locality: 0.8,
spatial_locality: 0.6,
read_write_ratio: 0.9,
target_hit_rate: 0.95,
latency_sensitivity: 0.7,
};
assert_eq!(profile.request_rate, 100.0);
assert_eq!(profile.working_set_size, 1024);
assert_eq!(profile.read_write_ratio, 0.9);
}
#[test]
fn test_cache_diagnostics_reexport() {
let effectiveness = CacheEffectiveness {
overall_hit_rate: 0.85,
memory_efficiency: 0.9,
time_saved_ms: 1000,
most_valuable_caches: vec![("ast".to_string(), 0.95)],
};
let diagnostics = CacheDiagnostics {
session_id: uuid::Uuid::new_v4(),
uptime: Duration::from_secs(3600),
memory_usage_mb: 256.0,
memory_pressure: 0.3,
cache_stats: vec![],
hot_paths: vec![],
effectiveness,
};
let _ = format!("{:?}", diagnostics);
}
#[test]
fn test_cache_effectiveness_reexport() {
let effectiveness = CacheEffectiveness {
overall_hit_rate: 0.85,
memory_efficiency: 0.9,
time_saved_ms: 1000,
most_valuable_caches: vec![],
};
let _ = format!("{:?}", effectiveness);
assert_eq!(effectiveness.overall_hit_rate, 0.85);
}
#[test]
fn test_content_cache_reexport() {
let _cache_type: std::any::TypeId =
std::any::TypeId::of::<ContentCache<AstCacheStrategy>>();
}
#[test]
fn test_session_cache_manager_reexport() {
let _type_id = std::any::TypeId::of::<SessionCacheManager>();
}
#[test]
fn test_persistent_cache_manager_creation() {
let temp_dir = tempfile::TempDir::new().unwrap();
let config = CacheConfig::default();
let manager = PersistentCacheManager::new(config, temp_dir.path().to_path_buf());
let _ = manager;
}
#[test]
fn test_cache_entry_access_increments_count() {
let entry = CacheEntry::new("value".to_string(), 50);
assert_eq!(entry.access_count.load(Ordering::Relaxed), 0);
entry.access();
assert_eq!(entry.access_count.load(Ordering::Relaxed), 1);
entry.access();
entry.access();
assert_eq!(entry.access_count.load(Ordering::Relaxed), 3);
}
#[test]
fn test_cache_entry_age() {
let entry = CacheEntry::new("value".to_string(), 50);
let age = entry.age();
assert!(age < Duration::from_secs(1));
}
#[test]
fn test_cache_entry_last_accessed_duration() {
let entry = CacheEntry::new("value".to_string(), 50);
let last_accessed = entry.last_accessed_duration();
assert!(last_accessed < Duration::from_secs(1));
entry.access();
let after_access = entry.last_accessed_duration();
assert!(after_access < Duration::from_secs(1));
}
#[test]
fn test_cache_entry_clone() {
let entry = CacheEntry::new("value".to_string(), 50);
entry.access();
entry.access();
let cloned = entry.clone();
assert_eq!(*cloned.value, "value");
assert_eq!(cloned.size_bytes, 50);
assert_eq!(cloned.access_count.load(Ordering::Relaxed), 2);
}
#[test]
fn test_cache_stats_default() {
let stats = CacheStats::default();
assert_eq!(stats.hits.load(Ordering::Relaxed), 0);
assert_eq!(stats.misses.load(Ordering::Relaxed), 0);
assert_eq!(stats.evictions.load(Ordering::Relaxed), 0);
assert_eq!(stats.total_bytes.load(Ordering::Relaxed), 0);
}
#[test]
fn test_cache_stats_hit_rate_empty() {
let stats = CacheStats::new();
assert_eq!(stats.hit_rate(), 0.0);
}
#[test]
fn test_cache_stats_hit_rate_all_hits() {
let stats = CacheStats::new();
stats.record_hit();
stats.record_hit();
stats.record_hit();
assert_eq!(stats.hit_rate(), 1.0);
}
#[test]
fn test_cache_stats_hit_rate_all_misses() {
let stats = CacheStats::new();
stats.record_miss();
stats.record_miss();
assert_eq!(stats.hit_rate(), 0.0);
}
#[test]
fn test_cache_stats_hit_rate_mixed() {
let stats = CacheStats::new();
stats.record_hit();
stats.record_hit();
stats.record_miss();
stats.record_miss();
assert!((stats.hit_rate() - 0.5).abs() < f64::EPSILON);
}
#[test]
fn test_cache_stats_total_requests() {
let stats = CacheStats::new();
assert_eq!(stats.total_requests(), 0);
stats.record_hit();
assert_eq!(stats.total_requests(), 1);
stats.record_miss();
assert_eq!(stats.total_requests(), 2);
stats.record_hit();
stats.record_miss();
assert_eq!(stats.total_requests(), 4);
}
#[test]
fn test_cache_stats_memory_usage() {
let stats = CacheStats::new();
assert_eq!(stats.memory_usage(), 0);
stats.add_bytes(100);
assert_eq!(stats.memory_usage(), 100);
stats.add_bytes(200);
assert_eq!(stats.memory_usage(), 300);
stats.remove_bytes(50);
assert_eq!(stats.memory_usage(), 250);
}
#[test]
fn test_cache_stats_eviction_tracking() {
let stats = CacheStats::new();
assert_eq!(stats.evictions.load(Ordering::Relaxed), 0);
stats.record_eviction();
assert_eq!(stats.evictions.load(Ordering::Relaxed), 1);
stats.record_eviction();
stats.record_eviction();
assert_eq!(stats.evictions.load(Ordering::Relaxed), 3);
}
#[test]
fn test_cache_stats_clone() {
let stats = CacheStats::new();
stats.record_hit();
stats.add_bytes(100);
let cloned = stats.clone();
assert_eq!(cloned.hits.load(Ordering::Relaxed), 1);
assert_eq!(cloned.total_bytes.load(Ordering::Relaxed), 100);
stats.record_hit();
assert_eq!(cloned.hits.load(Ordering::Relaxed), 2);
}
#[test]
fn test_cache_stats_debug() {
let stats = CacheStats::new();
let debug_str = format!("{:?}", stats);
assert!(debug_str.contains("CacheStats"));
assert!(debug_str.contains("hits"));
assert!(debug_str.contains("misses"));
}
#[test]
fn test_all_strategies_have_positive_max_size() {
assert!(AstCacheStrategy.max_size() > 0);
assert!(TemplateCacheStrategy.max_size() > 0);
assert!(DagCacheStrategy.max_size() > 0);
assert!(ChurnCacheStrategy.max_size() > 0);
assert!(GitStatsCacheStrategy.max_size() > 0);
}
#[test]
fn test_all_strategies_have_ttl() {
assert!(AstCacheStrategy.ttl().is_some());
assert!(TemplateCacheStrategy.ttl().is_some());
assert!(DagCacheStrategy.ttl().is_some());
assert!(ChurnCacheStrategy.ttl().is_some());
assert!(GitStatsCacheStrategy.ttl().is_some());
}
#[test]
fn test_ast_cache_manager_trait_exists() {
fn _accepts_ast_cache_manager<T: AstCacheManager>(_: &T) {}
}
}