use std::time::Duration;
#[cfg(feature = "fake-clock")]
use sn_fake_clock::FakeClock as Instant;
use qlrumap::LruMap;
#[cfg(test)]
fn delay(secs: u64) {
#[cfg(not(feature = "sn_fake_clock"))]
std::thread::sleep(Duration::from_secs(secs));
#[cfg(feature = "sn_fake_clock")]
Instant::advance_time(secs * 1000);
}
#[test]
fn single_entry() {
let ttl = Duration::from_secs(1);
let mut map = LruMap::with_ttl(ttl);
map.insert("hello", "world");
assert_eq!(map.youngest(), Some((&"hello", &"world")));
assert_eq!(map.oldest(), Some((&"hello", &"world")));
delay(1);
map.insert("moo", "cow");
assert_eq!(map.youngest(), Some((&"moo", &"cow")));
assert_eq!(map.oldest(), Some((&"hello", &"world")));
delay(1);
map.insert("meow", "cat");
assert_eq!(map.youngest(), Some((&"meow", &"cat")));
assert_eq!(map.oldest(), Some((&"hello", &"world")));
delay(1);
map.touch("moo");
assert_eq!(map.youngest(), Some((&"moo", &"cow")));
assert_eq!(map.oldest(), Some((&"hello", &"world")));
}