GCC Code Coverage Report


Directory: ./
File: lib/my/my_sort_params.c
Date: 2024-06-05 00:34:38
Exec Total Coverage
Lines: 34 34 100.0%
Functions: 4 4 100.0%
Branches: 20 20 100.0%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2023
3 ** my_sort_params
4 ** File description:
5 ** Sorts the arguments (argc and argv) passed to the program in ascending order
6 */
7 /**
8 * @file my_sort_params.c
9 * @brief The file containing the my_sort_params function
10 * @author Nicolas TORO
11 */
12
13 #include "my.h"
14
15 14 static int check_equal(int len_s1, int len_s2, int j, int littlest_char_index)
16 {
17
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13 times.
14 if (len_s1 < len_s2)
18 1 return j;
19
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 11 times.
13 else if (len_s1 > len_s2)
20 2 return littlest_char_index;
21 else
22 11 return littlest_char_index;
23 }
24
25 18 static int check_littlest(char **argv, int j, int littlest_char_index)
26 {
27 18 int i = 0;
28
29 129 while (i < my_strlen(argv[littlest_char_index])
30
4/4
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 12 times.
✓ Branch 3 taken 115 times.
✓ Branch 4 taken 2 times.
129 && i < my_strlen(argv[j])) {
31
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 112 times.
115 if (argv[littlest_char_index][i] < argv[j][i])
32 3 return j;
33
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 111 times.
112 if (argv[littlest_char_index][i] > argv[j][i])
34 1 return littlest_char_index;
35 111 i++;
36 }
37 14 return check_equal(my_strlen(argv[littlest_char_index]),
38 14 my_strlen(argv[j]), j, littlest_char_index);
39 }
40
41 9 static void check_swap(char **argv, int i, int littlest_char_index)
42 {
43 char *temp;
44
45
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5 times.
9 if (i != littlest_char_index) {
46 4 temp = argv[i];
47 4 argv[i] = argv[littlest_char_index];
48 4 argv[littlest_char_index] = temp;
49 }
50 9 }
51
52 3 void my_sort_params(int argc, char **argv)
53 {
54 3 int littlest_char_index = 0;
55
56
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 for (int i = 0; i < argc; i++) {
57 9 littlest_char_index = i;
58
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for (int j = i; j < argc; j++)
59 18 littlest_char_index = check_littlest(argv, j, littlest_char_index);
60 9 check_swap(argv, i, littlest_char_index);
61 }
62
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 for (int i = argc; i > 0; i--) {
63 9 my_putstr(argv[i - 1]);
64 9 my_putstr("\n");
65 }
66 3 }
67