forked from p93542168/wheat-cache
test(listx): test range
This commit is contained in:
parent
8883abd461
commit
74e42e78ac
|
@ -177,3 +177,30 @@ func TestListx_Slice(t *testing.T) {
|
|||
values, _ = list3.LPop(list3.Length())
|
||||
require.Equal(t, values, []string{"1", "2", "3", "4"})
|
||||
}
|
||||
|
||||
func TestListx_Range(t *testing.T) {
|
||||
list := NewListXSingle()
|
||||
list.RPush("a", "b", "c", "d", "e")
|
||||
val, err := list.Range(0, 2)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, val, []string{"a", "b"})
|
||||
|
||||
val, err = list.Range(0, -1)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, val, []string{"a", "b", "c", "d"})
|
||||
|
||||
val, err = list.Range(-3, 3)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, val, []string{"c"})
|
||||
|
||||
val, err = list.Range(-1, list.Length())
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, val, []string{})
|
||||
|
||||
_, err = list.Range(6, -1)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue