MCPcopy Index your code
hub / github.com/perkeep/perkeep / TestLRU

Function TestLRU

internal/lru/cache_test.go:24–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestLRU(t *testing.T) {
25 c := New(2)
26
27 expectMiss := func(k string) {
28 v, ok := c.Get(k)
29 if ok {
30 t.Fatalf("expected cache miss on key %q but hit value %v", k, v)
31 }
32 }
33
34 expectHit := func(k string, ev interface{}) {
35 v, ok := c.Get(k)
36 if !ok {
37 t.Fatalf("expected cache(%q)=%v; but missed", k, ev)
38 }
39 if !reflect.DeepEqual(v, ev) {
40 t.Fatalf("expected cache(%q)=%v; but got %v", k, ev, v)
41 }
42 }
43
44 expectMiss("1")
45 c.Add("1", "one")
46 expectHit("1", "one")
47
48 c.Add("2", "two")
49 expectHit("1", "one")
50 expectHit("2", "two")
51
52 c.Add("3", "three")
53 expectHit("3", "three")
54 expectHit("2", "two")
55 expectMiss("1")
56}
57
58func TestRemoveOldest(t *testing.T) {
59 c := New(2)

Callers

nothing calls this directly

Calls 4

NewFunction · 0.70
GetMethod · 0.65
FatalfMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected