Skip to content

Commit a4e52c0

Browse files
committed
Add coverage
1 parent 8f48847 commit a4e52c0

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,21 @@ endef
6262
$(eval $(call mk-profile, release, SRC, , $(BIN_NAME), 0))
6363
$(eval $(call mk-profile, debug, SRC, -D U_DEBUG_MODE -g3, libcuddle_debug.a, \
6464
0))
65-
$(eval $(call mk-profile, test, SRC, -D U_DEBUG_MODE -g3, test, 1))
65+
$(eval $(call mk-profile, test, SRC, -D U_DEBUG_MODE -g3 --coverage, test, 1))
6666

6767
all: $(NAME_release)
6868

69+
.PHONY: tests_run
70+
tests_run: $(NAME_test)
71+
./test tests/type.csv
72+
73+
.PHONY: cov
74+
cov: tests_run
75+
gcovr . \
76+
--gcov-ignore-errors=no_working_dir_found \
77+
--exclude-unreachable-branches \
78+
--exclude tests
79+
6980
clean:
7081
@ $(RM) $(OBJ)
7182
@ $(LOG_TIME) "$(C_YELLOW) RM $(C_PURPLE) $(OBJ) $(C_RESET)"

tests/main.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <stdint.h>
99
#include <stdio.h>
1010
#include <stdlib.h>
11+
#include <string.h>
1112

1213
#include "dataframe.h"
1314
#include "debug.h"
@@ -24,12 +25,13 @@ bool filter_func(void *vl)
2425

2526
void *apply_func(void *value)
2627
{
27-
int *new_value = malloc(sizeof(int));
28+
char *str = strdup((char *)value);
2829

29-
if (new_value == NULL)
30+
if (str == NULL)
3031
return NULL;
31-
*new_value = *(int *)value * 2;
32-
return new_value;
32+
if (str[strlen(str) - 1] == 'e')
33+
str[strlen(str) - 1] = '\0';
34+
return str;
3335
}
3436

3537
static
@@ -56,14 +58,24 @@ void print_df(int rows, int col, void ***data, column_type_t type)
5658

5759
int main(int ac, char **av)
5860
{
59-
dataframe_t *src = df_read_csv(av[1], ";");
60-
dataframe_t *df = df_apply(src, "age", apply_func);
61+
dataframe_t *src = df_read_csv(av[1], NULL);
62+
dataframe_t *int_df = df_apply(src, "amount", apply_func);
63+
dataframe_t *dst = df_to_type(int_df, "amount", INT);
64+
dataframe_t *df = df_sort(dst, "amount", sort_func);
6165

6266
if (df == NULL)
6367
return 84;
6468
df_write_csv(df, "result.csv");
6569
printf("nb_columns= %d\n", df->nb_columns);
6670
printf("nb_rows= %d\n", df->nb_rows);
71+
df_info(df);
72+
df_describe(df);
73+
df_shape(df);
74+
df_filter(df, "amount", filter_func);
75+
df_head(df, 1);
76+
df_tail(df, 1);
77+
df_get_value(df, 0, "amount");
78+
df_get_values(df, "amount");
6779
#if defined(U_DEBUG_MODE)
6880
printf("columns: ");
6981
for (int a = 0; a < df->nb_columns; a++)
@@ -78,5 +90,7 @@ int main(int ac, char **av)
7890
}
7991
df_free(src);
8092
df_free(df);
93+
df_free(int_df);
94+
df_free(dst);
8195
return 0;
8296
}

tests/type.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name,amount
2+
Alice,1e
3+
Bob,3e
4+
Léo,2e

0 commit comments

Comments
 (0)