基本上完善到我理想中的样子了

This commit is contained in:
建峰 2025-04-30 15:01:55 +08:00
parent ccae6a9d8f
commit 32f2605656
2 changed files with 7 additions and 7 deletions

View File

@ -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;
} }

View File

@ -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));