mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-05-18 03:51:35 +08:00
添加函数注释
This commit is contained in:
parent
643d601c6e
commit
e49f425e43
15
src/list.c
15
src/list.c
@ -189,6 +189,21 @@ static void list_print(struct _list* self)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief list slice
|
||||||
|
* if index < 0, from the end of list. for example:
|
||||||
|
* list[-1] is the last element in list.
|
||||||
|
*
|
||||||
|
* @param self
|
||||||
|
* @param start start index
|
||||||
|
* @param end end index
|
||||||
|
* @param step step, if step < 0, return a reverse list.
|
||||||
|
* @return struct _list*
|
||||||
|
* a copy of the list, from start to end, step by step.
|
||||||
|
* if step < 0, return a reverse list.
|
||||||
|
* if step > 0, return a forward list.
|
||||||
|
* if step == 0, return NULL.
|
||||||
|
*/
|
||||||
struct _list* list_slice(struct _list *self, int start, int end, int step)
|
struct _list* list_slice(struct _list *self, int start, int end, int step)
|
||||||
{
|
{
|
||||||
assert(self != NULL);
|
assert(self != NULL);
|
||||||
|
@ -440,14 +440,20 @@ static void test_list_slice(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// python: list[0:] -> []
|
// python: list[0:] -> []
|
||||||
list2 = list->slice(list, 0, 0, 1); // if start == end
|
|
||||||
TEST_ASSERT_NULL(list2);
|
|
||||||
|
|
||||||
list2 = list->slice(list, 1, 5, 0); // if step == 0
|
list2 = list->slice(list, 1, 5, 0); // if step == 0
|
||||||
TEST_ASSERT_NULL(list2);
|
TEST_ASSERT_NULL(list2);
|
||||||
|
|
||||||
|
list2 = list->slice(list, 0, 0, 1); // if start == end
|
||||||
|
TEST_ASSERT_NOT_NULL(list2);
|
||||||
|
TEST_ASSERT_TRUE(list2->empty(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_NULL(list2);
|
TEST_ASSERT_NULL(list2);
|
||||||
|
TEST_ASSERT_TRUE(list2->empty(list2));
|
||||||
|
|
||||||
|
list2 = list->slice(list, 5, 1, 1); // if start > end && step > 0
|
||||||
|
TEST_ASSERT_NULL(list2);
|
||||||
|
TEST_ASSERT_TRUE(list2->empty(list2));
|
||||||
|
|
||||||
// python: list[0:]
|
// python: list[0:]
|
||||||
list2 = list->slice(list, 0, len, 1);
|
list2 = list->slice(list, 0, len, 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user