sine_cache 0.2.0

SineCache is a high-performance, in-memory caching library for Rust, designed to efficiently store and manage key-value pairs with support for various eviction policies.
Documentation
//! Unit tests regarding FIFO

use crate::{eviction_policies::fifo::FIFO};
use crate::eviction_policies::common::EvictionPolicy;

#[test]
fn test_new_fifo() {
    let mut fifo: FIFO<i32> = FIFO::new();
    assert!(fifo.evict().is_none());
}

#[test]
fn test_on_set_and_evict() {
    let mut fifo: FIFO<i32> = FIFO::new();
    let key1 = 1;
    let key2 = 2;

    fifo.on_set(key1.clone());
    fifo.on_set(key2.clone());

    assert_eq!(fifo.evict(), Some(key1));
    assert_eq!(fifo.evict(), Some(key2));
    assert_eq!(fifo.evict(), None);
}

#[test]
fn test_evict() {
    let mut fifo: FIFO<i32> = FIFO::new();
    let key1 = 1;
    let key2 = 2;
    let key3 = 3;

    fifo.on_set(key1.clone());
    fifo.on_set(key2.clone());
    fifo.on_set(key3.clone());

    assert_eq!(fifo.evict(), Some(key1));
    assert_eq!(fifo.evict(), Some(key2));
    assert_eq!(fifo.evict(), Some(key3));
    assert_eq!(fifo.evict(), None);
}

#[test]
fn test_remove_and_evict() {
    let mut fifo: FIFO<i32> = FIFO::new();
    let key1 = 1;
    let key2 = 2;

    fifo.on_set(key1.clone());
    fifo.on_set(key2.clone());
    fifo.remove(key1.clone());

    assert_eq!(fifo.evict(), Some(key2));
    assert_eq!(fifo.evict(), None);
}

#[test]
fn test_evict_with_tombstones() {
    let mut fifo: FIFO<i32> = FIFO::new();
    let key1 = 1;
    let key2 = 2;
    let key3 = 3;

    fifo.on_set(key1.clone());
    fifo.on_set(key2.clone());
    fifo.on_set(key3.clone());
    fifo.remove(key1.clone());
    fifo.remove(key2.clone());

    assert_eq!(fifo.evict(), Some(key3));
    assert_eq!(fifo.evict(), None);
}

#[test]
fn test_on_get() {
    let mut fifo: FIFO<i32> = FIFO::new();
    let key1 = 1;
    fifo.on_set(key1.clone());
    fifo.on_get(&key1);
    // On_get should not affect the queue, no assertions needed here.
}