diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-02-16 04:51:41 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-02-16 04:51:41 +0100 |
| commit | 01b4cc91d1596cf94d709a627ed8ad64bc1e285d (patch) | |
| tree | 8b15a7758247ed4d4a084bccefedbf426ddfd305 /test/src/lst/test_ft_lstiter.c | |
| parent | bf4dc8e5c1dbb8149f0cab473f73b5e9bac24ae0 (diff) | |
| download | libft-01b4cc91d1596cf94d709a627ed8ad64bc1e285d.tar.gz libft-01b4cc91d1596cf94d709a627ed8ad64bc1e285d.tar.bz2 libft-01b4cc91d1596cf94d709a627ed8ad64bc1e285d.zip | |
Filled lst* tests
Diffstat (limited to 'test/src/lst/test_ft_lstiter.c')
| -rw-r--r-- | test/src/lst/test_ft_lstiter.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/src/lst/test_ft_lstiter.c b/test/src/lst/test_ft_lstiter.c index 20a1511..c8bf90d 100644 --- a/test/src/lst/test_ft_lstiter.c +++ b/test/src/lst/test_ft_lstiter.c @@ -8,7 +8,45 @@ TEST_SETUP(ft_lstiter) TEST_TEAR_DOWN(ft_lstiter) {} +static void square_iter_func(void *data) +{ + int *d = (int*)data; + + *d = *d * *d; +} + TEST(ft_lstiter, basic) { + t_ftlst *lst = NULL; + int a = 2; + int b = 3; + int c = 4; + int d = 5; + + ft_lstiter(lst, square_iter_func); + TEST_ASSERT_NULL(lst); + + ft_lstadd_front(&lst, ft_lstnew(&a)); + ft_lstiter(lst, square_iter_func); + TEST_ASSERT_EQUAL(4, *(int*)lst->content); + + ft_lstadd_front(&lst, ft_lstnew(&b)); + ft_lstiter(lst, square_iter_func); + TEST_ASSERT_EQUAL(9, *(int*)lst->content); + TEST_ASSERT_EQUAL(16, *(int*)lst->next->content); + + ft_lstadd_front(&lst, ft_lstnew(&c)); + ft_lstiter(lst, square_iter_func); + TEST_ASSERT_EQUAL(16, *(int*)lst->content); + TEST_ASSERT_EQUAL(81, *(int*)lst->next->content); + TEST_ASSERT_EQUAL(256, *(int*)lst->next->next->content); + + ft_lstadd_front(&lst, ft_lstnew(&d)); + ft_lstiter(lst, square_iter_func); + TEST_ASSERT_EQUAL(25, *(int*)lst->content); + TEST_ASSERT_EQUAL(256, *(int*)lst->next->content); + TEST_ASSERT_EQUAL(81 * 81, *(int*)lst->next->next->content); + TEST_ASSERT_EQUAL(256 * 256, *(int*)lst->next->next->next->content); + ft_lstclear(&lst, NULL); } |
