mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-05-17 19:41:36 +08:00
基本上完善到我理想中的样子了
This commit is contained in:
parent
ccae6a9d8f
commit
32f2605656
@ -283,14 +283,9 @@ struct _list* list_slice(struct _list* self, int start, int end, int step)
|
|||||||
list->compare = self->compare;
|
list->compare = self->compare;
|
||||||
list->print_obj = self->print_obj;
|
list->print_obj = self->print_obj;
|
||||||
|
|
||||||
if (start > size || end > size)
|
|
||||||
{
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (step > 0)
|
if (step > 0)
|
||||||
{
|
{
|
||||||
if (start > end)
|
if (start >= end)
|
||||||
{
|
{
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@ -312,7 +307,7 @@ struct _list* list_slice(struct _list* self, int start, int end, int step)
|
|||||||
}
|
}
|
||||||
else /*if(step < 0)*/
|
else /*if(step < 0)*/
|
||||||
{
|
{
|
||||||
if (start < end)
|
if (start <= end)
|
||||||
{
|
{
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
@ -451,6 +451,11 @@ static void test_list_slice_empty(void)
|
|||||||
TEST_ASSERT_TRUE(list2->empty(list2));
|
TEST_ASSERT_TRUE(list2->empty(list2));
|
||||||
list_free(&list2);
|
list_free(&list2);
|
||||||
|
|
||||||
|
list2 = list->slice(list, len, LIST_UNLIMITED, 1); // if start == end
|
||||||
|
TEST_ASSERT_NOT_NULL(list2);
|
||||||
|
TEST_ASSERT_TRUE(list2->empty(list2));
|
||||||
|
list_free(&list2);
|
||||||
|
|
||||||
list2 = list->slice(list, 1, 5, -1); // if start < end && step < 0
|
list2 = list->slice(list, 1, 5, -1); // if start < end && step < 0
|
||||||
TEST_ASSERT_NOT_NULL(list2);
|
TEST_ASSERT_NOT_NULL(list2);
|
||||||
TEST_ASSERT_TRUE(list2->empty(list2));
|
TEST_ASSERT_TRUE(list2->empty(list2));
|
||||||
|
Loading…
Reference in New Issue
Block a user