Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
** EPITECH PROJECT, 2024 |
3 |
|
|
** test_mylist_lib |
4 |
|
|
** File description: |
5 |
|
|
** Unit tests for each function of the mylist lib |
6 |
|
|
*/ |
7 |
|
|
/** |
8 |
|
|
* @file test_mylist_lib.c |
9 |
|
|
* @brief Unit tests for each function of the mylist lib |
10 |
|
|
* @author Nicolas TORO |
11 |
|
|
*/ |
12 |
|
|
|
13 |
|
|
#include "criterion/criterion.h" |
14 |
|
|
#include "criterion/redirect.h" |
15 |
|
|
#include "../lib/mylist/mylist.h" |
16 |
|
|
|
17 |
|
4 |
Test(my_concat_list, my_concat_list) |
18 |
|
|
{ |
19 |
|
2 |
node_t *list1 = NULL; |
20 |
|
2 |
node_t *list2 = NULL; |
21 |
|
2 |
node_t *list3 = NULL; |
22 |
|
|
|
23 |
|
2 |
my_push_back(&list1, "Hello", STRING); |
24 |
|
2 |
my_push_back(&list1, "World", STRING); |
25 |
|
2 |
my_push_back(&list1, "World", STRING); |
26 |
|
2 |
my_push_back(&list1, "World", STRING); |
27 |
|
2 |
my_push_back(&list1, "World", STRING); |
28 |
|
2 |
my_push_back(&list1, "World", STRING); |
29 |
|
2 |
my_push_back(&list2, "Bonjour", STRING); |
30 |
|
2 |
my_push_back(&list2, "Monde", STRING); |
31 |
|
2 |
my_concat_list(&list1, list2); |
32 |
|
2 |
my_concat_list(&list3, list2); |
33 |
|
2 |
} |
34 |
|
|
|
35 |
|
4 |
Test(my_delete_nodes, my_delete_nodes) |
36 |
|
|
{ |
37 |
|
2 |
node_t *list = NULL; |
38 |
|
2 |
int nodes_deleted = 0; |
39 |
|
2 |
char *str1 = my_strdup("World"); |
40 |
|
2 |
char *str2 = my_strdup("Hellow"); |
41 |
|
2 |
char *str3 = my_strdup("World"); |
42 |
|
|
|
43 |
|
2 |
my_push_back(&list, str1, STRING); |
44 |
|
2 |
my_push_back(&list, str2, STRING); |
45 |
|
2 |
my_push_back(&list, str3, STRING); |
46 |
|
2 |
my_delete_nodes(&list, "World", my_strcmp); |
47 |
|
2 |
nodes_deleted = my_delete_nodes(&list, "World", my_strcmp); |
48 |
|
2 |
} |
49 |
|
|
|
50 |
|
4 |
Test(my_find_node, my_find_node) |
51 |
|
|
{ |
52 |
|
2 |
node_t *list = NULL; |
53 |
|
2 |
node_t *node = NULL; |
54 |
|
2 |
char *str1 = my_strdup("World"); |
55 |
|
2 |
char *str2 = my_strdup("Hellow"); |
56 |
|
2 |
char *str3 = my_strdup("World"); |
57 |
|
|
|
58 |
|
2 |
my_push_back(&list, str1, STRING); |
59 |
|
2 |
my_push_back(&list, str2, STRING); |
60 |
|
2 |
my_push_back(&list, str3, STRING); |
61 |
|
2 |
node = my_find_node(list, "World", my_strcmp); |
62 |
|
2 |
node = my_find_node(list, "Helloooo", my_strcmp); |
63 |
|
2 |
} |
64 |
|
|
|
65 |
|
4 |
Test(my_list_size, my_list_size) |
66 |
|
|
{ |
67 |
|
2 |
node_t *list = NULL; |
68 |
|
2 |
int size = 0; |
69 |
|
2 |
char *str1 = my_strdup("World"); |
70 |
|
2 |
char *str2 = my_strdup("Hellow"); |
71 |
|
2 |
char *str3 = my_strdup("World"); |
72 |
|
|
|
73 |
|
2 |
my_push_back(&list, str1, STRING); |
74 |
|
2 |
my_push_back(&list, str2, STRING); |
75 |
|
2 |
my_push_back(&list, str3, STRING); |
76 |
|
2 |
size = my_list_size(list); |
77 |
|
2 |
} |
78 |
|
|
|
79 |
|
4 |
Test(my_list_to_array, my_list_to_array) |
80 |
|
|
{ |
81 |
|
2 |
node_t *list = NULL; |
82 |
|
2 |
char **array = NULL; |
83 |
|
2 |
char *str1 = my_strdup("World"); |
84 |
|
2 |
char *str2 = my_strdup("Hellow"); |
85 |
|
2 |
char *str3 = my_strdup("World"); |
86 |
|
|
|
87 |
|
2 |
my_push_back(&list, str1, STRING); |
88 |
|
2 |
my_push_back(&list, str2, STRING); |
89 |
|
2 |
my_push_back(&list, str3, STRING); |
90 |
|
2 |
array = (char **)my_list_to_array(list); |
91 |
|
2 |
array = (char **)my_list_to_array(list); |
92 |
|
2 |
} |
93 |
|
|
|
94 |
|
4 |
Test(my_merge_list, my_merge_list) |
95 |
|
|
{ |
96 |
|
2 |
node_t *list1 = NULL; |
97 |
|
2 |
node_t *list2 = NULL; |
98 |
|
2 |
node_t *list3 = NULL; |
99 |
|
2 |
char *str1 = my_strdup("World"); |
100 |
|
2 |
char *str2 = my_strdup("Hellow"); |
101 |
|
2 |
char *str3 = my_strdup("World"); |
102 |
|
2 |
char *str4 = my_strdup("World!"); |
103 |
|
|
|
104 |
|
2 |
my_push_back(&list1, str1, STRING); |
105 |
|
2 |
my_push_back(&list1, str2, STRING); |
106 |
|
2 |
my_push_back(&list1, str3, STRING); |
107 |
|
2 |
my_push_back(&list2, str1, STRING); |
108 |
|
2 |
my_push_back(&list2, str2, STRING); |
109 |
|
2 |
my_push_back(&list2, str4, STRING); |
110 |
|
2 |
my_merge_list(&list1, list2, my_strcmp); |
111 |
|
2 |
my_merge_list(&list3, list2, my_strcmp); |
112 |
|
2 |
} |
113 |
|
|
|
114 |
|
4 |
Test(my_params_to_list, my_params_to_list) |
115 |
|
|
{ |
116 |
|
2 |
node_t *list = NULL; |
117 |
|
2 |
char *av[] = {"Hello", "World", "Bonjour", "Monde"}; |
118 |
|
2 |
int ac = 4; |
119 |
|
|
|
120 |
|
2 |
list = my_params_to_list(ac, av); |
121 |
|
2 |
list = my_params_to_list(ac, av); |
122 |
|
2 |
} |
123 |
|
|
|
124 |
|
4 |
Test(my_pop_back, my_pop_back) |
125 |
|
|
{ |
126 |
|
2 |
node_t *list = NULL; |
127 |
|
2 |
node_t *node = NULL; |
128 |
|
2 |
node_t *list2 = NULL; |
129 |
|
2 |
char *str1 = my_strdup("World"); |
130 |
|
2 |
char *str2 = my_strdup("Hellow"); |
131 |
|
2 |
char *str3 = my_strdup("World"); |
132 |
|
|
|
133 |
|
2 |
my_push_back(&list, str1, STRING); |
134 |
|
2 |
my_push_back(&list, str2, STRING); |
135 |
|
2 |
my_push_back(&list, str3, STRING); |
136 |
|
2 |
node = my_pop_back(&list); |
137 |
|
2 |
node = my_pop_back(&list); |
138 |
|
2 |
my_pop_back(&list2); |
139 |
|
2 |
my_push_back(&list2, str1, STRING); |
140 |
|
2 |
my_pop_back(&list2); |
141 |
|
2 |
} |
142 |
|
|
|
143 |
|
4 |
Test(my_pop_front, my_pop_front) |
144 |
|
|
{ |
145 |
|
2 |
node_t *list = NULL; |
146 |
|
2 |
node_t *node = NULL; |
147 |
|
2 |
char *str1 = my_strdup("World"); |
148 |
|
2 |
char *str2 = my_strdup("Hellow"); |
149 |
|
2 |
char *str3 = my_strdup("World"); |
150 |
|
|
|
151 |
|
2 |
my_push_back(&list, str1, STRING); |
152 |
|
2 |
my_push_back(&list, str2, STRING); |
153 |
|
2 |
my_push_back(&list, str3, STRING); |
154 |
|
2 |
node = my_pop_front(&list); |
155 |
|
2 |
node = my_pop_front(&list); |
156 |
|
2 |
list = NULL; |
157 |
|
2 |
my_pop_front(&list); |
158 |
|
2 |
} |
159 |
|
|
|
160 |
|
4 |
Test(my_pop_node, my_pop_node) |
161 |
|
|
{ |
162 |
|
2 |
node_t *list = NULL; |
163 |
|
2 |
node_t *node = NULL; |
164 |
|
2 |
char *str1 = my_strdup("World"); |
165 |
|
2 |
char *str2 = my_strdup("Hellow"); |
166 |
|
2 |
char *str3 = my_strdup("World"); |
167 |
|
2 |
char *str4 = my_strdup("Hello!"); |
168 |
|
|
|
169 |
|
2 |
my_push_back(&list, str1, STRING); |
170 |
|
2 |
my_push_back(&list, str2, STRING); |
171 |
|
2 |
my_push_back(&list, str3, STRING); |
172 |
|
2 |
my_push_back(&list, str4, STRING); |
173 |
|
2 |
node = my_pop_node(&list, "Hello!", my_strcmp); |
174 |
|
2 |
node = my_pop_node(&list, "World", my_strcmp); |
175 |
|
2 |
node = my_pop_node(&list, "Hello", my_strcmp); |
176 |
|
2 |
} |
177 |
|
|
|
178 |
|
4 |
Test(my_rev_list, my_rev_list) |
179 |
|
|
{ |
180 |
|
2 |
node_t *list = NULL; |
181 |
|
2 |
char *str1 = my_strdup("World"); |
182 |
|
2 |
char *str2 = my_strdup("Hellow"); |
183 |
|
2 |
char *str3 = my_strdup("World"); |
184 |
|
|
|
185 |
|
2 |
my_push_back(&list, str1, STRING); |
186 |
|
2 |
my_push_back(&list, str2, STRING); |
187 |
|
2 |
my_push_back(&list, str3, STRING); |
188 |
|
2 |
my_rev_list(&list); |
189 |
|
2 |
} |
190 |
|
|
|
191 |
|
4 |
Test(my_show_list, my_show_list) |
192 |
|
|
{ |
193 |
|
2 |
node_t *list = NULL; |
194 |
|
2 |
char c = 42; |
195 |
|
2 |
char *str = my_strdup("World"); |
196 |
|
2 |
int nb1 = 42; |
197 |
|
2 |
short nb2 = 42; |
198 |
|
2 |
char nb3 = 42; |
199 |
|
2 |
long nb4 = 42; |
200 |
|
2 |
long long nb5 = 42; |
201 |
|
2 |
unsigned char nb6 = 42; |
202 |
|
2 |
unsigned short nb7 = 42; |
203 |
|
2 |
unsigned int nb8 = 42; |
204 |
|
2 |
unsigned long nb9 = 42; |
205 |
|
2 |
unsigned long long nb10 = 42; |
206 |
|
2 |
size_t nb11 = 42; |
207 |
|
2 |
float nb12 = 42.42; |
208 |
|
2 |
double nb13 = 42.42; |
209 |
|
2 |
void *ptr = NULL; |
210 |
|
2 |
char **array = NULL; |
211 |
|
|
|
212 |
|
2 |
my_push_back(&list, str, STRING); |
213 |
|
2 |
my_push_back(&list, &c, CHAR); |
214 |
|
2 |
my_push_back(&list, &nb1, INT); |
215 |
|
2 |
my_push_back(&list, &nb2, SHORT); |
216 |
|
2 |
my_push_back(&list, &nb3, SHORT_SHORT); |
217 |
|
2 |
my_push_back(&list, &nb4, LONG); |
218 |
|
2 |
my_push_back(&list, &nb5, LONG_LONG); |
219 |
|
2 |
my_push_back(&list, &nb6, UNSIGNED_SHORT_SHORT); |
220 |
|
2 |
my_push_back(&list, &nb7, UNSIGNED_SHORT); |
221 |
|
2 |
my_push_back(&list, &nb8, UNSIGNED_INT); |
222 |
|
2 |
my_push_back(&list, &nb9, UNSIGNED_LONG); |
223 |
|
2 |
my_push_back(&list, &nb10, UNSIGNED_LONG_LONG); |
224 |
|
2 |
my_push_back(&list, &nb11, SIZE_T); |
225 |
|
2 |
my_push_back(&list, &nb12, FLOAT); |
226 |
|
2 |
my_push_back(&list, &nb13, DOUBLE); |
227 |
|
2 |
my_push_back(&list, &ptr, VOID); |
228 |
|
2 |
my_push_back(&list, &array, ARRAY_OF_STRING); |
229 |
|
2 |
my_push_back(&list, &ptr, UNKNOWN); |
230 |
|
2 |
my_show_list(list); |
231 |
|
2 |
} |
232 |
|
|
|
233 |
|
4 |
Test(my_sort_list, my_sort_list) |
234 |
|
|
{ |
235 |
|
2 |
node_t *list = NULL; |
236 |
|
2 |
char *str1 = my_strdup("World"); |
237 |
|
2 |
char *str2 = my_strdup("Hellow"); |
238 |
|
2 |
char *str3 = my_strdup("World"); |
239 |
|
|
|
240 |
|
2 |
my_push_back(&list, str1, STRING); |
241 |
|
2 |
my_push_back(&list, str2, STRING); |
242 |
|
2 |
my_push_back(&list, str3, STRING); |
243 |
|
2 |
my_sort_list(&list, my_strcmp); |
244 |
|
2 |
} |
245 |
|
|
|