-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstadd_front_test.c
48 lines (45 loc) · 2.25 KB
/
ft_lstadd_front_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abenamar <abenamar@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/15 00:01:01 by abenamar #+# #+# */
/* Updated: 2022/12/28 22:18:19 by abenamar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft_test.h"
void ft_lstadd_front_test(void)
{
t_list *lst;
t_list *item;
printf(RESET "\nft_lstadd_front\t");
int a = 0;
lst = ft_lstnew(&a);
int b = 1;
ft_lstadd_front(&lst, ft_lstnew(&b));
ft_assert(1, (*(int *)(lst->content) == 1 && *(int *)(lst->next->content) == 0));
int c = 2;
ft_lstadd_front(&lst, ft_lstnew(&c));
ft_assert(2, (*(int *)(lst->content) == 2 && *(int *)(lst->next->content) == 1 && *(int *)(lst->next->next->content) == 0));
int d = 3;
ft_lstadd_front(&lst, ft_lstnew(&d));
ft_assert(3, (*(int *)(lst->content) == 3 && *(int *)(lst->next->content) == 2
&& *(int *)(lst->next->next->content) == 1 && *(int *)(lst->next->next->next->content) == 0));
int e = 4;
ft_lstadd_front(&lst, ft_lstnew(&e));
ft_assert(4, (*(int *)(lst->content) == 4 && *(int *)(lst->next->content) == 3 && *(int *)(lst->next->next->content) == 2
&& *(int *)(lst->next->next->next->content) == 1 && *(int *)(lst->next->next->next->next->content) == 0));
int f = 5;
ft_lstadd_front(&lst, ft_lstnew(&f));
ft_assert(5, (*(int *)(lst->content) == 5 && *(int *)(lst->next->content) == 4
&& *(int *)(lst->next->next->content) == 3 && *(int *)(lst->next->next->next->content) == 2
&& *(int *)(lst->next->next->next->next->content) == 1 && *(int *)(lst->next->next->next->next->next->content) == 0));
while (lst)
{
item = lst->next;
free(lst);
lst = item;
}
}