use triviumdb::database::{Config, Database};
#[test]
fn test_fatigue_and_specificity_ablation() {
let temp_dir = std::env::temp_dir().join(format!("triviumdb_ablation_{}", std::process::id()));
if temp_dir.exists() {
std::fs::remove_dir_all(&temp_dir).unwrap();
}
let db_path = temp_dir.join("fatigue.tdb");
let config = Config {
dim: 2,
..Default::default()
};
let mut db = Database::open_with_config(db_path.to_str().unwrap(), config).unwrap();
let search_config = triviumdb::database::SearchConfig {
expand_depth: 3,
top_k: 20,
enable_advanced_pipeline: true,
enable_dpp: false,
enable_refractory_fatigue: true, teleport_alpha: 0.1, ..Default::default()
};
let blackhole_id = db
.insert(&[1.0, 0.0], serde_json::json!({"name": "blackhole"}))
.unwrap();
let src_id = db
.insert(&[0.8, 0.6], serde_json::json!({"name": "source"}))
.unwrap();
let leaf_id = db
.insert(&[0.6, 0.8], serde_json::json!({"name": "leaf"}))
.unwrap();
for i in 0..100 {
let dummy = db
.insert(
&[0.0, 1.0],
serde_json::json!({"name": format!("dummy_{}", i)}),
)
.unwrap();
db.link(dummy, blackhole_id, "link", 1.0).unwrap();
}
db.link(src_id, blackhole_id, "link", 1.0).unwrap();
db.link(src_id, leaf_id, "link", 1.0).unwrap();
let hits1 = db.search_advanced(&[0.8, 0.6], &search_config).unwrap();
let bh_score1 = hits1
.iter()
.find(|h| h.id == blackhole_id)
.map(|h| h.score)
.unwrap_or(0.0);
let lf_score1 = hits1
.iter()
.find(|h| h.id == leaf_id)
.map(|h| h.score)
.unwrap_or(0.0);
println!("=== Round 1 (Fresh Edge Specificity) ===");
println!("Blackhole Score: {}", bh_score1);
println!("Leaf Score: {}", lf_score1);
let hits2 = db.search_advanced(&[0.8, 0.6], &search_config).unwrap();
let bh_score2 = hits2
.iter()
.find(|h| h.id == blackhole_id)
.map(|h| h.score)
.unwrap_or(0.0);
let lf_score2 = hits2
.iter()
.find(|h| h.id == leaf_id)
.map(|h| h.score)
.unwrap_or(0.0);
println!("=== Round 2 (Fatigue Engaged) ===");
println!("Blackhole Score: {}", bh_score2);
println!("Leaf Score: {}", lf_score2);
assert!(
bh_score2 < bh_score1 * 0.5,
"Fatigue didn't drastically decay the blackhole score!"
);
let hits3 = db.search_advanced(&[0.8, 0.6], &search_config).unwrap();
let bh_score3 = hits3
.iter()
.find(|h| h.id == blackhole_id)
.map(|h| h.score)
.unwrap_or(0.0);
println!("=== Round 3 (Fatigue Restored) ===");
println!("Blackhole Score: {}", bh_score3);
assert!(
bh_score3 > bh_score2,
"不应期解除后黑洞得分应回升!Round2(疲劳抑制)={}, Round3(恢复)={}",
bh_score2,
bh_score3
);
let _ = std::fs::remove_dir_all(&temp_dir);
}