GCC Code Coverage Report


Directory: ./
File: lib/my/my_print_combn.c
Date: 2024-06-05 00:36:48
Exec Total Coverage
Lines: 34 34 100.0%
Functions: 3 3 100.0%
Branches: 18 18 100.0%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2023
3 ** my_print_combn
4 ** File description:
5 ** Prints all the numbers composed by (n) different digits numbers
6 ** All digits in the number are different and only the smallest
7 ** number composed by those digits are display
8 */
9 /**
10 * @file my_print_combn.c
11 * @brief The file containing the my_print_combn function
12 * @author Nicolas TORO
13 */
14
15 #include "my.h"
16
17 1561 static char *str_number_to_int(int nb, int n)
18 {
19 1561 int len_nb = 1;
20 1561 int temp_nb = nb;
21 char *nb_str;
22 1561 int figure_temp = nb;
23 1561 int nb_zero = 0;
24
25
2/2
✓ Branch 0 taken 2940 times.
✓ Branch 1 taken 1561 times.
4501 while ((temp_nb / 10) != 0) {
26 2940 len_nb = len_nb + 1;
27 2940 temp_nb = temp_nb / 10;
28 }
29 1561 nb_str = malloc(sizeof(char) * n);
30
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1561 times.
1571 for (; nb_zero < n - len_nb - 1; nb_zero++)
31 10 nb_str[nb_zero] = '0';
32
2/2
✓ Branch 0 taken 4683 times.
✓ Branch 1 taken 1561 times.
6244 for (int i = 0; i < n; i++) {
33 4683 nb_str[n - i - 1 + nb_zero] = 48 + (figure_temp % 10);
34 4683 figure_temp = (figure_temp - (figure_temp % 10)) / 10;
35 }
36 1561 nb_str[n] = '\0';
37 1561 return nb_str;
38 }
39
40 1561 static int check_printable(char *number, int figure, int *start)
41 {
42
2/2
✓ Branch 0 taken 880 times.
✓ Branch 1 taken 681 times.
1561 if (number[figure - 1] >= number[figure])
43 880 return 1;
44
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 561 times.
681 if (figure - 1 == 0) {
45
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 119 times.
120 if (*start == 1)
46 1 *start = 0;
47 else {
48 119 my_putchar(',');
49 119 my_putchar(' ');
50 }
51 120 my_putstr(number);
52 }
53 681 return 0;
54 }
55
56 1 void my_print_combn(int n)
57 {
58 1 int stop = 0;
59 1 int start = 1;
60
61
2/2
✓ Branch 1 taken 1000 times.
✓ Branch 2 taken 1 times.
1001 for (int number = 0; number < my_compute_power_rec(10, n); number++) {
62
4/4
✓ Branch 0 taken 2441 times.
✓ Branch 1 taken 120 times.
✓ Branch 2 taken 1561 times.
✓ Branch 3 taken 880 times.
2561 for (int figure = n - 1; figure >= 0 && stop == 0; figure--) {
63 1561 stop = check_printable(str_number_to_int(number, n),
64 figure, &start);
65 }
66 1000 stop = 0;
67 }
68 1 }
69