From 9e1a139928e158e3393f85b3d7a2db959f550648 Mon Sep 17 00:00:00 2001 From: Nikita Stroganov Date: Sun, 26 Feb 2023 09:46:23 +0000 Subject: [PATCH] Add an access time update check after Cache.Get --- lrucache/cache_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lrucache/cache_test.go b/lrucache/cache_test.go index fadbf92..1596b12 100644 --- a/lrucache/cache_test.go +++ b/lrucache/cache_test.go @@ -29,6 +29,29 @@ func TestCache_update(t *testing.T) { require.Equal(t, 2, v) } +func TestCache_Get(t *testing.T) { + c := New(5) + + for i := 0; i < 5; i++ { + c.Set(i, i) + } + + c.Get(0) + c.Get(1) + + c.Set(5, 5) + c.Set(6, 6) + + var keys, values []int + c.Range(func(key, value int) bool { + keys = append(keys, key) + values = append(values, value) + return true + }) + require.Equal(t, []int{4, 0, 1, 5, 6}, keys) + require.Equal(t, []int{4, 0, 1, 5, 6}, values) +} + func TestCache_Clear(t *testing.T) { c := New(5)