MCPcopy
hub / github.com/go-gorm/gorm / TestLRUNoPurge

Function TestLRUNoPurge

tests/lru_test.go:175–220  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

173}
174
175func TestLRUNoPurge(t *testing.T) {
176 lc := lru.NewLRU[string, string](10, nil, 0)
177
178 lc.Add("key1", "val1")
179 if lc.Len() != 1 {
180 t.Fatalf("length differs from expected")
181 }
182
183 v, ok := lc.Peek("key1")
184 if v != "val1" {
185 t.Fatalf("value differs from expected")
186 }
187 if !ok {
188 t.Fatalf("should be true")
189 }
190
191 if !lc.Contains("key1") {
192 t.Fatalf("should contain key1")
193 }
194 if lc.Contains("key2") {
195 t.Fatalf("should not contain key2")
196 }
197
198 v, ok = lc.Peek("key2")
199 if v != "" {
200 t.Fatalf("should be empty")
201 }
202 if ok {
203 t.Fatalf("should be false")
204 }
205
206 if !reflect.DeepEqual(lc.Keys(), []string{"key1"}) {
207 t.Fatalf("value differs from expected")
208 }
209
210 if lc.Resize(0) != 0 {
211 t.Fatalf("evicted count differs from expected")
212 }
213 if lc.Resize(2) != 0 {
214 t.Fatalf("evicted count differs from expected")
215 }
216 lc.Add("key2", "val2")
217 if lc.Resize(1) != 1 {
218 t.Fatalf("evicted count differs from expected")
219 }
220}
221
222func TestLRUEdgeCases(t *testing.T) {
223 lc := lru.NewLRU[string, *string](2, nil, 0)

Callers

nothing calls this directly

Calls 7

NewLRUFunction · 0.92
AddMethod · 0.80
LenMethod · 0.80
PeekMethod · 0.80
ContainsMethod · 0.80
ResizeMethod · 0.80
KeysMethod · 0.65

Tested by

no test coverage detected