From f7abb56e926d0904e59e9c72cca7a4c316a0366b Mon Sep 17 00:00:00 2001 From: HuangJiaLuo <1820799930@qq.com> Date: Sat, 21 Aug 2021 22:27:00 +0800 Subject: [PATCH] Test --- pkg/lru/LRU.go | 45 +++++++++++++++++++++++++++++++++++++++ pkg/lru/define/define.go | 4 +++- pkg/lru/test/Hello.go | 5 +++++ pkg/lru/test/HelloTest.go | 11 ++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 pkg/lru/LRU.go create mode 100644 pkg/lru/test/Hello.go create mode 100644 pkg/lru/test/HelloTest.go diff --git a/pkg/lru/LRU.go b/pkg/lru/LRU.go new file mode 100644 index 0000000..001c778 --- /dev/null +++ b/pkg/lru/LRU.go @@ -0,0 +1,45 @@ +package lru + +import ( + "container/list" + "gitee.com/timedb/wheatCache/pkg/lru/define" +) + +type CacheNode struct { + value int + key string +} + +type Cache struct { + cache map[string]*list.Element + li *list.List + size int // LRU的长度 + MaxByte int64 // 允许的最大存储 + NowByte int64 // 目前的存储 +} + +// 创建一个LRU +func NewLRU() *Cache { + return &Cache{ + MaxByte: define.MaxByte, + size: 0, + NowByte: 0, + cache: make(map[string]*list.Element), + } +} + +// +func GetLRU() { + +} + +// +func (c *Cache) AddLRU(key string, value int) { + + c.size += 1 +} + +//获取链表长度 +func (c *Cache) GetLRULength() int { + return c.size +} diff --git a/pkg/lru/define/define.go b/pkg/lru/define/define.go index 8c5bf99..125529a 100644 --- a/pkg/lru/define/define.go +++ b/pkg/lru/define/define.go @@ -1,3 +1,5 @@ package define -// define +const ( + MaxByte = 1024 +) diff --git a/pkg/lru/test/Hello.go b/pkg/lru/test/Hello.go new file mode 100644 index 0000000..cacae6d --- /dev/null +++ b/pkg/lru/test/Hello.go @@ -0,0 +1,5 @@ +package test + +func Hello(str string) (bool, error) { + return str == "Hello", nil +} diff --git a/pkg/lru/test/HelloTest.go b/pkg/lru/test/HelloTest.go new file mode 100644 index 0000000..9a8e626 --- /dev/null +++ b/pkg/lru/test/HelloTest.go @@ -0,0 +1,11 @@ +package test + +import ( + "github.com/stretchr/testify/require" + "testing" +) + +func TestHello(t *testing.T) { + _, err := Hello("Hello") + require.NoError(t, err) +}