use chaotic_semantic_memory::prelude::*;
const NS: &str = "_default";
#[tokio::test]
async fn cache_hit_updates_lru_order() {
let framework = ChaoticSemanticFramework::builder()
.without_persistence()
.with_concept_cache_size(4)
.build()
.await
.unwrap();
let vec_a = HVec10240::random();
framework.inject_concept("a", vec_a).await.unwrap();
framework
.inject_concept("b", HVec10240::random())
.await
.unwrap();
framework
.inject_concept("c", HVec10240::random())
.await
.unwrap();
framework
.inject_concept("d", HVec10240::random())
.await
.unwrap();
let results1 = framework.probe(vec_a, 2).await.unwrap();
assert!(results1.iter().any(|(id, _)| id == "a"));
let results2 = framework.probe(vec_a, 2).await.unwrap();
assert!(results2.iter().any(|(id, _)| id == "a"));
framework
.inject_concept("e", HVec10240::random())
.await
.unwrap();
let results3 = framework.probe(vec_a, 5).await.unwrap();
assert!(results3.iter().any(|(id, _)| id == "a"));
}
#[tokio::test]
async fn cache_capacity_eviction() {
let framework = ChaoticSemanticFramework::builder()
.without_persistence()
.with_concept_cache_size(2) .build()
.await
.unwrap();
let vec1 = HVec10240::random();
framework.inject_concept("c1", vec1).await.unwrap();
framework
.inject_concept("c2", HVec10240::random())
.await
.unwrap();
framework.probe(vec1, 1).await.unwrap();
framework.probe(HVec10240::random(), 1).await.unwrap();
framework.probe(vec1, 1).await.unwrap();
}
#[tokio::test]
async fn cache_clear_removes_all_entries() {
let framework = ChaoticSemanticFramework::builder()
.without_persistence()
.with_concept_cache_size(16)
.build()
.await
.unwrap();
let vec1 = HVec10240::random();
framework.inject_concept("x", vec1).await.unwrap();
framework.probe(vec1, 1).await.unwrap();
framework.clear_similarity_cache().await;
framework.probe(vec1, 1).await.unwrap();
}