From 74e42e78ac2dd0d724a55fcb2d5079822a173f73 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Fri, 22 Oct 2021 22:01:58 +0800 Subject: [PATCH] test(listx): test range --- pkg/structure/listx/listx_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/structure/listx/listx_test.go b/pkg/structure/listx/listx_test.go index c0fd034..bc34617 100644 --- a/pkg/structure/listx/listx_test.go +++ b/pkg/structure/listx/listx_test.go @@ -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) +}