parent
d49f187da6
commit
4fc1cae2da
@ -0,0 +1,23 @@
|
|||||||
|
### Go template
|
||||||
|
# If you prefer the allow list template instead of the deny list, see community template:
|
||||||
|
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
||||||
|
#
|
||||||
|
# Binaries for programs and plugins
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Test binary, built with `go test -c`
|
||||||
|
*.test
|
||||||
|
|
||||||
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
|
*.out
|
||||||
|
|
||||||
|
# Dependency directories (remove the comment below to include it)
|
||||||
|
# vendor/
|
||||||
|
|
||||||
|
# Go workspace file
|
||||||
|
go.work
|
||||||
|
|
@ -0,0 +1,34 @@
|
|||||||
|
package lfu_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"cache/lfu"
|
||||||
|
"github.com/matryer/is"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSet(t *testing.T) {
|
||||||
|
is := is.New(t)
|
||||||
|
cache := lfu.New(24, nil)
|
||||||
|
cache.DelOldest()
|
||||||
|
cache.Set("k1", 1)
|
||||||
|
v := cache.Get("k1")
|
||||||
|
is.Equal(v, 1)
|
||||||
|
cache.Del("k1")
|
||||||
|
is.Equal(0, cache.Len())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOnEvicted(t *testing.T) {
|
||||||
|
is := is.New(t)
|
||||||
|
keys := make([]string, 0, 8)
|
||||||
|
onEvicted := func(key string, value interface{}) {
|
||||||
|
keys = append(keys, key)
|
||||||
|
}
|
||||||
|
cache := lfu.New(32, onEvicted)
|
||||||
|
cache.Set("k1", 1)
|
||||||
|
cache.Set("k2", 2)
|
||||||
|
cache.Set("k3", 3)
|
||||||
|
cache.Set("k4", 4)
|
||||||
|
expected := []string{"k1", "k3"}
|
||||||
|
is.Equal(expected, keys)
|
||||||
|
is.Equal(2, cache.Len())
|
||||||
|
}
|
Loading…
Reference in new issue