use keyhog_verifier::testing::{
evict_oldest_dashmap_survivors_for_test as survivors, oldest_eviction_batch,
};
#[test]
fn oldest_eviction_batch_is_one_eighth_of_cap() {
assert_eq!(oldest_eviction_batch(4096), 512);
assert_eq!(oldest_eviction_batch(16), 2);
assert_eq!(oldest_eviction_batch(8), 1);
}
#[test]
fn oldest_eviction_batch_never_returns_zero() {
assert_eq!(oldest_eviction_batch(7), 1);
assert_eq!(oldest_eviction_batch(1), 1);
assert_eq!(oldest_eviction_batch(0), 1);
}
#[test]
fn evict_oldest_removes_the_count_oldest_and_keeps_the_newest() {
let ages: Vec<u64> = (0..16).collect();
assert_eq!(survivors(&ages, 4), (4..16).collect::<Vec<u64>>());
}
#[test]
fn evict_oldest_count_zero_is_a_noop() {
assert_eq!(survivors(&[5, 1, 3], 0), vec![1, 3, 5]);
}
#[test]
fn evict_oldest_count_at_or_above_len_evicts_everything() {
assert_eq!(survivors(&[5, 1, 3], 3), Vec::<u64>::new());
assert_eq!(survivors(&[5, 1, 3], 9), Vec::<u64>::new());
}
#[test]
fn batch_and_evict_compose_to_the_bounded_cache_contract() {
let cap = 4096usize;
let batch = oldest_eviction_batch(cap);
let ages: Vec<u64> = (0..cap as u64).collect();
let remaining = survivors(&ages, batch);
assert_eq!(remaining.len(), cap - batch);
assert_eq!(remaining.first().copied(), Some(batch as u64));
assert_eq!(remaining.last().copied(), Some(cap as u64 - 1));
}