40 lines
873 B
Go
40 lines
873 B
Go
package lru
|
|
|
|
import (
|
|
"fmt"
|
|
"gitee.com/timedb/wheatCache/pkg/structure/stringx"
|
|
"github.com/stretchr/testify/require"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewLRUCache(t *testing.T) {
|
|
cache := NewLRUCache()
|
|
v1 := stringx.NewStringSingle()
|
|
v2 := stringx.NewStringSingle()
|
|
v3 := stringx.NewStringSingle()
|
|
cache.Add("1", v1)
|
|
cache.Add("2", v2)
|
|
cache.Add("3", v3)
|
|
cache.Add("1", v1)
|
|
fmt.Println(cache.nowSize)
|
|
cache.Del()
|
|
fmt.Println(cache.nowSize)
|
|
_, isTrue := cache.Get("1")
|
|
require.Equal(t, isTrue, false)
|
|
}
|
|
|
|
func TestSingleCache_DelToClearSize(t *testing.T) {
|
|
cache := NewLRUCache()
|
|
v1 := stringx.NewStringSingle()
|
|
v2 := stringx.NewStringSingle()
|
|
//v3 := stringx.NewStringSingle()
|
|
//v4 := stringx.NewStringSingle()
|
|
cache.Add("1", v1)
|
|
cache.Add("2", v2)
|
|
res, ok := cache.Get("1")
|
|
if ok {
|
|
fmt.Println(res)
|
|
}
|
|
_, ok = cache.Get("1")
|
|
require.Equal(t, ok, false)
|
|
} |