GCC Code Coverage Report


Directory: ./
File: lib/my/my_printf/sub_format_double.c
Date: 2024-06-05 00:34:38
Exec Total Coverage
Lines: 53 53 100.0%
Functions: 7 7 100.0%
Branches: 28 42 66.7%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2023
3 ** my_printf
4 ** File description:
5 ** The functions for format a double
6 */
7 /**
8 * @file sub_format_double.c
9 * @brief The file containing the sub_format_double functions
10 * @author Nicolas TORO
11 */
12
13 #include "myprintf.h"
14
15 7 static void do_next(char *str_finale, formating_t *formating, double nb)
16 {
17 7 void (*format[])(char *, formating_t *, double) =
18 {&format_moins_double, &format_plus_double, &format_esp_double,
19 &format_hash_double, &format_zero_double};
20
21
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 6 times.
38 for (int j = 0; j < 5; j++) {
22
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 31 times.
32 if (formating->next_chara == FORMATAGE[j]) {
23 1 format[j](str_finale, formating, nb);
24 1 return;
25 }
26 }
27 }
28
29 2 static void en_plus(char *str_finale, formating_t *formating)
30 {
31
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
4 for (int i = my_strlen(str_finale); i < formating->id_wd; i++)
32 2 my_strcat(str_finale, " ");
33 2 }
34
35 2 void format_plus_double(char *str_finale, formating_t *formating, double nb)
36 {
37
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (nb >= 0) {
38 2 my_revstr(str_finale);
39 2 my_strcat(str_finale, "+");
40
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (formating->id_wd != -1)
41 2 en_plus(str_finale, formating);
42 2 my_revstr(str_finale);
43 }
44 2 }
45
46 1 void format_moins_double(char *str_finale, formating_t *formating, double nb)
47 {
48
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if ((my_strlen(str_finale) < formating->id_wd
49
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 && formating->next_chara == '+')
50
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 || my_strlen(str_finale) < formating->id_wd) {
51
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 times.
4 for (int i = my_strlen(str_finale); i < formating->id_wd; i++) {
52 3 my_strcat(str_finale, " ");
53 }
54 }
55 1 do_next(str_finale, formating, nb);
56 1 }
57
58 5 void format_esp_double(char *str_finale, formating_t *formating, double nb)
59 {
60 5 do_next(str_finale, formating, nb);
61 5 my_revstr(str_finale);
62
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 5 times.
9 for (int i = my_strlen(str_finale); i < formating->id_wd; i++)
63 4 my_strcat(str_finale, " ");
64
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
5 if (formating->id_wd == -1 && formating->next_chara != '+'
65
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 && formating->id_prc == -1)
66 1 my_strcat(str_finale, " ");
67
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 if (formating->id_wd != -1
68
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
4 && my_strlen(str_finale) > formating->id_wd
69
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1 && (formating->flag == 'a' || formating->flag == 'A'))
70 1 my_strcat(str_finale, " ");
71 5 my_revstr(str_finale);
72 5 }
73
74 1 void format_zero_double(char *str_finale, formating_t *formating, double nb)
75 {
76 1 long long int i = my_strlen(str_finale);
77
78 1 my_revstr(str_finale);
79
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 for (i;(i < formating->id_wd && formating->next_chara != '+')
80
3/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2 || (i < formating->id_wd - 1 && formating->next_chara == '+')
81 1 ; i++)
82 1 my_strcat(str_finale, "0");
83 1 my_revstr(str_finale);
84 1 do_next(str_finale, formating, nb);
85 1 }
86
87 2 void format_hash_double(char *str_finale, formating_t *formating, double nb)
88 {
89 2 format_esp_double(str_finale, formating, nb);
90 2 return;
91 }
92