()
| 816 | |
| 817 | #[test] |
| 818 | fn test_hit_rate_calculation() { |
| 819 | let cache = TtlCache::new(); |
| 820 | |
| 821 | cache.insert("key1".to_string(), "value1".to_string()); |
| 822 | |
| 823 | // 2 hits, 1 miss |
| 824 | cache.get(&"key1".to_string()); |
| 825 | cache.get(&"key1".to_string()); |
| 826 | cache.get(&"nonexistent".to_string()); |
| 827 | |
| 828 | let stats = cache.stats(); |
| 829 | assert!((stats.hit_rate() - 0.6666666666666666).abs() < 0.0001); |
| 830 | } |
| 831 | |
| 832 | #[test] |
| 833 | fn test_cache_factory() { |