forked from p93542168/wheat-cache
Compare commits
2 Commits
master
...
test-dao-l
Author | SHA1 | Date |
---|---|---|
bandl | 8014cf7e1a | |
Pyroo | ead796d7c2 |
|
@ -162,7 +162,7 @@ func (l *Listx) LPush(valueStr ...string) structure.UpdateLength {
|
|||
|
||||
// 使用第一个元素尝试初始化列表
|
||||
updateLength := l.initByValue(valueStr[0])
|
||||
for i := 1; i < len(valueStr); i++ {
|
||||
for i := 0; i < len(valueStr); i++ {
|
||||
head := l.head
|
||||
val := structure.NewValue(valueStr[i])
|
||||
node := &ListxNode{val: val}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package dao
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitee.com/wheat-os/wheatCache/pkg/lru"
|
||||
"gitee.com/wheat-os/wheatCache/pkg/proto"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDao_LPush_LPop(t *testing.T) {
|
||||
baseKey := proto.NewBaseKey("s")
|
||||
lru := lru.NewLRUCache()
|
||||
dao := NewDao(lru)
|
||||
|
||||
_, err := dao.LPush(baseKey, []string{"abc", "bcd"})
|
||||
require.NoError(t, err)
|
||||
_, err = dao.LPush(baseKey, []string{"a", "b"})
|
||||
require.NoError(t, err)
|
||||
_, err = dao.LPush(baseKey, []string{"c", "d"})
|
||||
require.NoError(t, err)
|
||||
resp, err := dao.LPop(baseKey, 5)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, resp.Results, []string{"d", "b", "bcd", "abc"})
|
||||
_, err = dao.LPush(baseKey, []string{"a", "b"})
|
||||
require.NoError(t, err)
|
||||
resp, err = dao.LPop(baseKey, 1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, resp.Results, []string{"b"})
|
||||
_, err = dao.LPush(baseKey, []string{"d"})
|
||||
require.NoError(t, err)
|
||||
resp, err = dao.LPop(baseKey, 1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, resp.Results, []string{})
|
||||
// resp, err = dao.LPop(baseKey, 1)
|
||||
// require.NoError(t, err)
|
||||
// require.Equal(t, resp.Results, []string{"bcd"})
|
||||
// resp, err = dao.LPop(baseKey, 0)
|
||||
// require.NoError(t, err)
|
||||
// require.Equal(t, resp.Results, []string{})
|
||||
|
||||
// _, err = dao.LPush(baseKey, []string{"b"})
|
||||
// require.NoError(t, err)
|
||||
// resp, err = dao.LPop(baseKey, 3)
|
||||
// require.NoError(t, err)
|
||||
// require.Equal(t, resp.Results, []string{"a", "b", "abc"})
|
||||
}
|
Loading…
Reference in New Issue