GCC Code Coverage Report


Directory: ./
File: lib/my/my_str_nbr_short.c
Date: 2024-06-05 00:36:48
Exec Total Coverage
Lines: 24 24 100.0%
Functions: 2 2 100.0%
Branches: 10 10 100.0%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2023
3 ** my_str_nbr_short
4 ** File description:
5 ** Returns the string conversion of a short number (nb)
6 */
7 /**
8 * @file my_str_nbr_short.c
9 * @brief The file containing the my_str_nbr_short function
10 * @author Nicolas TORO
11 */
12
13 #include "my.h"
14
15 6 static char *set_str_nb(short int nb, int int_nb, int signe)
16 {
17 6 char *nb_str = malloc(sizeof(char) * (int_nb + signe + 1));
18 6 int j = 0;
19 6 short int figure_temp = nb;
20
21
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
6 if (signe == 1)
22 1 nb_str[int_nb] = '-';
23
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 6 times.
17 for (j = 0; j < int_nb; j++) {
24 11 nb_str[j] = 48 + (figure_temp % 10);
25 11 figure_temp = (figure_temp - (figure_temp % 10)) / 10;
26 }
27 6 nb_str[j + signe] = '\0';
28 6 return my_revstr(nb_str);
29 }
30
31 7 char *my_str_nbr_short(short int nb)
32 {
33 7 int int_nb = 1;
34 7 short temp_nb = nb;
35 7 int signe = 0;
36
37
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
7 if (nb == -32768)
38 1 return "-32768";
39
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
6 if (nb < 0) {
40 1 signe = 1;
41 1 nb = -nb;
42 }
43
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
11 while ((temp_nb / 10) != 0) {
44 5 int_nb = int_nb + 1;
45 5 temp_nb = temp_nb / 10;
46 }
47 6 return set_str_nb(nb, int_nb, signe);
48 }
49