GCC Code Coverage Report


Directory: ./
File: lib/my/my_print_combn.c
Date: 2024-06-05 00:29:21
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 #include <stdlib.h>
11 #include "my.h"
12
13 1561 static char *str_number_to_int(int nb, int n)
14 {
15 1561 int len_nb = 1;
16 1561 int temp_nb = nb;
17 char *nb_str;
18 1561 int figure_temp = nb;
19 1561 int nb_zero = 0;
20
21
2/2
✓ Branch 0 taken 2940 times.
✓ Branch 1 taken 1561 times.
4501 while ((temp_nb / 10) != 0) {
22 2940 len_nb = len_nb + 1;
23 2940 temp_nb = temp_nb / 10;
24 }
25 1561 nb_str = malloc(sizeof(char) * n);
26
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1561 times.
1571 for (; nb_zero < n - len_nb - 1; nb_zero++)
27 10 nb_str[nb_zero] = '0';
28
2/2
✓ Branch 0 taken 4683 times.
✓ Branch 1 taken 1561 times.
6244 for (int i = 0; i < n; i++) {
29 4683 nb_str[n - i - 1 + nb_zero] = 48 + (figure_temp % 10);
30 4683 figure_temp = (figure_temp - (figure_temp % 10)) / 10;
31 }
32 1561 nb_str[n] = '\0';
33 1561 return nb_str;
34 }
35
36 1561 static int check_printable(char *number, int figure, int *start)
37 {
38
2/2
✓ Branch 0 taken 880 times.
✓ Branch 1 taken 681 times.
1561 if (number[figure - 1] >= number[figure])
39 880 return 1;
40
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 561 times.
681 if (figure - 1 == 0) {
41
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 119 times.
120 if (*start == 1)
42 1 *start = 0;
43 else {
44 119 my_putchar(',');
45 119 my_putchar(' ');
46 }
47 120 my_putstr(number);
48 }
49 681 return 0;
50 }
51
52 1 int my_print_combn(int n)
53 {
54 1 int stop = 0;
55 1 int start = 1;
56
57
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++) {
58
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--) {
59 1561 stop = check_printable(str_number_to_int(number, n),
60 figure, &start);
61 }
62 1000 stop = 0;
63 }
64 1 return 0;
65 }
66