GCC Code Coverage Report


Directory: ./
File: lib/my/my_round_float_str.c
Date: 2024-06-05 02:24:39
Exec Total Coverage
Lines: 24 26 92.3%
Functions: 2 2 100.0%
Branches: 19 22 86.4%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2023
3 ** my_printf
4 ** File description:
5 ** Modify a string (float) and round it
6 */
7 /**
8 * @file my_round_float_str.c
9 * @brief The file containing the my_round_float_str function
10 * @author Nicolas TORO
11 */
12
13 #include "my.h"
14
15 1 static void add_number(char *float_nb)
16 {
17 1 char *temp_float_str = malloc(sizeof(char) * my_strlen(float_nb + 1));
18
19 1 temp_float_str[0] = '1';
20 1 my_strcat(temp_float_str, float_nb);
21 1 my_strcpy(float_nb, temp_float_str);
22
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (float_nb[1] == '-') {
23 float_nb[1] = float_nb[0];
24 float_nb[0] = '-';
25 }
26 1 FREE(temp_float_str);
27 1 }
28
29 71 void my_round_float_str(char *float_nb, char last_char, int i, int enable)
30 {
31
3/4
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 70 times.
71 if (float_nb[i] == '\0' || float_nb[i] == '-')
32 1 add_number(float_nb);
33
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 67 times.
71 if (float_nb[i] == '.') {
34
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (float_nb[i - 1] == '9')
35 1 float_nb[i - 1] = '0';
36 else
37 3 float_nb[i - 1] = float_nb[i - 1] + 1;
38
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (float_nb[i - 1] == '0')
39 1 my_round_float_str(float_nb, float_nb[i - 1], i - 2, 0);
40 4 return;
41 }
42
5/6
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
✓ Branch 3 taken 11 times.
✓ Branch 4 taken 23 times.
✓ Branch 5 taken 33 times.
67 if (float_nb[i] != '.' && (last_char > '4' || enable == 1)) {
43
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 11 times.
34 if (float_nb[i] == '9')
44 23 float_nb[i] = '0';
45 else
46 11 float_nb[i] = float_nb[i] + 1;
47
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 11 times.
34 if (float_nb[i] == '0')
48 23 my_round_float_str(float_nb, float_nb[i], i - 1, 1);
49 }
50 }
51