GCC Code Coverage Report


Directory: ./
File: lib/mylist/my_pop_node.c
Date: 2024-06-05 00:36:48
Exec Total Coverage
Lines: 18 18 100.0%
Functions: 2 2 100.0%
Branches: 10 14 71.4%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2024
3 ** my_pop_list
4 ** File description:
5 ** Return the last node of a linked list and remove it from the list
6 */
7 /**
8 * @file my_pop_node.c
9 * @brief The file containing the my_pop_node function
10 * @author Nicolas TORO
11 */
12
13 #include "mylist.h"
14
15 2 static void change_list(node_t **begin, node_t *tmp)
16 {
17
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (tmp->prev != NULL)
18 1 tmp->prev->next = tmp->next;
19 else
20 1 *begin = tmp->next;
21
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (tmp->next != NULL)
22 1 tmp->next->prev = tmp->prev;
23 2 }
24
25 3 node_t *my_pop_node(node_t **begin, void const *data_ref, int (*cmp)())
26 {
27 3 node_t *tmp = *begin;
28 3 node_t *next = NULL;
29
30
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 while (tmp != NULL) {
31 7 next = tmp->next;
32
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7 if ((cmp == NULL && tmp->data == data_ref)
33
3/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 5 times.
7 || (cmp != NULL && cmp(tmp->data, data_ref) == 0)) {
34 2 change_list(begin, tmp);
35 2 return tmp;
36 }
37 5 tmp = next;
38 }
39 1 return NULL;
40 }
41