GCC Code Coverage Report


Directory: ./
File: lib/my/my_getnbr.c
Date: 2024-06-05 00:36:48
Exec Total Coverage
Lines: 25 25 100.0%
Functions: 2 2 100.0%
Branches: 21 22 95.5%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2023
3 ** my_getnbr
4 ** File description:
5 ** Returns an int number starting from a string number (str)
6 */
7 /**
8 * @file my_getnbr.c
9 * @brief The file containing the my_getnbr function
10 * @author Nicolas TORO
11 */
12
13 #include "my.h"
14
15 123 static int index_negative(char const *str, int index)
16 {
17
2/2
✓ Branch 0 taken 121 times.
✓ Branch 1 taken 2 times.
123 if (index == 0)
18 121 return 1;
19
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (str[index - 1] == '-')
20 1 return -1;
21 1 return 1;
22 }
23
24 125 int my_getnbr(char const *str)
25 {
26 125 int convert = 0;
27 125 int index = 0;
28 125 int index_neg = 1;
29 125 int index_int = 0;
30
31
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 124 times.
125 if (my_strcmp(str, "-2147483648") == 0)
32 1 return -2147483648;
33
6/6
✓ Branch 0 taken 122 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 121 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
124 if ((str[0] < '0' || str[0] > '9') && str[0] != '-')
34 1 return 0;
35
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 123 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 123 times.
126 while (str[index] < '0' || str[index] > '9')
36 3 index++;
37 123 index_neg = index_negative(str, index);
38
4/4
✓ Branch 0 taken 329 times.
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 247 times.
✓ Branch 3 taken 82 times.
370 while (str[index] >= '0' && str[index] <= '9') {
39 247 convert = convert * 10 + (str[index] - 48);
40 247 index++;
41 247 index_int++;
42
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 246 times.
247 if (index_int > 10)
43 1 convert = 0;
44 }
45 123 return index_neg * convert;
46 }
47