GCC Code Coverage Report


Directory: ./
File: lib/mylist/my_delete_nodes.c
Date: 2024-06-05 00:36:48
Exec Total Coverage
Lines: 22 22 100.0%
Functions: 2 2 100.0%
Branches: 11 16 68.8%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2023
3 ** my_delete_nodes
4 ** File description:
5 ** Deletes nodes from a linked list
6 */
7 /**
8 * @file my_delete_nodes.c
9 * @brief The file containing the my_delete_nodes function
10 * @author Nicolas TORO
11 */
12
13 #include "mylist.h"
14
15 2 static void remove_node(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
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (tmp->type != UNKNOWN)
24 2 FREE(tmp->data);
25 2 FREE(tmp);
26 2 }
27
28 2 int my_delete_nodes(node_t **begin, void const *data_ref, int (*cmp)())
29 {
30 2 node_t *tmp = *begin;
31 2 node_t *next = NULL;
32 2 int nodes_deleted = 0;
33
34
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 while (tmp != NULL) {
35 4 next = tmp->next;
36
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4 if ((cmp == NULL && tmp->data == data_ref)
37
3/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
4 || (cmp != NULL && cmp(tmp->data, data_ref) == 0)) {
38 2 remove_node(begin, tmp);
39 2 nodes_deleted++;
40 }
41 4 tmp = next;
42 }
43 2 return nodes_deleted;
44 }
45