diff options
author | Marc Pervaz Boocha <marcpervaz@qburst.com> | 2025-02-25 09:46:37 +0530 |
---|---|---|
committer | Marc Pervaz Boocha <marcpervaz@qburst.com> | 2025-02-27 13:38:02 +0530 |
commit | 4e6d37095c6c75632ca9c4af2cbb3276364c2e5a (patch) | |
tree | 22540501437a80f8c36d3075eb8372444f513ad4 /evict_test.go | |
parent | Added examples and documentation (diff) | |
download | cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar.gz cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar.bz2 cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar.lz cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar.xz cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar.zst cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.zip |
Add additional test cases to improve coverage and robustness
Diffstat (limited to '')
-rw-r--r-- | evict_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/evict_test.go b/evict_test.go index ba73c24..1813e94 100644 --- a/evict_test.go +++ b/evict_test.go @@ -86,6 +86,36 @@ func TestFIFOPolicy(t *testing.T) { assert.Nil(t, policy.Evict()) }) }) + + t.Run("Eviction Order", func(t *testing.T) { + t.Parallel() + + policy := lfuPolicy{evict: createSentinel(t)} + + n0 := &node{Key: []byte("0"), Access: 1} + n1 := &node{Key: []byte("1"), Access: 1} + + policy.OnInsert(n0) + policy.OnInsert(n1) + + evictedNode := policy.Evict() + assert.Same(t, n0, evictedNode) // Assuming FIFO order for same access count + }) + + t.Run("With Zero TTL", func(t *testing.T) { + t.Parallel() + + policy := ltrPolicy{evict: createSentinel(t), evictZero: false} + + n0 := &node{Key: []byte("0"), Expiration: time.Time{}} + n1 := &node{Key: []byte("1"), Expiration: time.Now().Add(1 * time.Hour)} + + policy.OnInsert(n0) + policy.OnInsert(n1) + + evictedNode := policy.Evict() + assert.Same(t, n1, evictedNode) // n0 should not be evicted due to zero TTL + }) } func TestLRUPolicy(t *testing.T) { |