blob: 5b2d2369c953a8a02d7ce25469cf02837b5dc33e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_list_sort_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/08 03:08:15 by cacharle #+# #+# */
/* Updated: 2020/11/07 17:15:22 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "libasm_test.h"
static
int compar_int(void *a, void *b)
{
return *(int*)a - *(int*)b;
}
static t_list *tmp;
static t_list *expected;
static t_list *actual;
static t_list *from;
#define FT_LIST_SORT_EXPECT(fmt) do { \
from = list_from_format(fmt); \
expected = list_from_format(fmt); \
actual = list_from_format(fmt); \
ref_ft_list_sort(&expected, compar_int); \
ft_list_sort(&actual, compar_int); \
if (list_cmp(expected, actual) != 0) { \
printf("KO: [COMPARE]: %s: expected: ", test_name); \
list_print(expected); \
printf(" got: "); \
list_print(actual); \
printf(" with: "); \
list_print(from); \
putchar('\n'); \
} else \
print_ok(); \
list_destroy(from); \
list_destroy(expected); \
list_destroy(actual); \
} while (0);
static
void ft_list_sort_segfault(void)
{
TEST_ASM_FUNCTION(tmp = list_from_format(""); ft_list_sort(&tmp, compar_int); list_destroy(tmp));
TEST_ASM_FUNCTION(tmp = list_from_format("1"); ft_list_sort(&tmp, compar_int); list_destroy(tmp));
TEST_ASM_FUNCTION(tmp = list_from_format("1 2"); ft_list_sort(&tmp, compar_int); list_destroy(tmp));
TEST_ASM_FUNCTION(tmp = list_from_format("1 2 3"); ft_list_sort(&tmp, compar_int); list_destroy(tmp));
TEST_ASM_FUNCTION(tmp = list_from_format("-1 0 1 2 3 4 5 6"); ft_list_sort(&tmp, compar_int); list_destroy(tmp));
TEST_ASM_FUNCTION(tmp = list_from_format("98 12 12 45 1 -1 232 34 23"); ft_list_sort(&tmp, compar_int); list_destroy(tmp));
TEST_ASM_FUNCTION(tmp = list_from_format("12 45 1 -1 232 34 23 87879"); ft_list_sort(&tmp, compar_int); list_destroy(tmp));
}
static
void ft_list_sort_compare(void)
{
FT_LIST_SORT_EXPECT("");
FT_LIST_SORT_EXPECT("1");
FT_LIST_SORT_EXPECT("1 2");
FT_LIST_SORT_EXPECT("1 2 3");
FT_LIST_SORT_EXPECT("-1 0 1 2 3 4 5 6");
FT_LIST_SORT_EXPECT("98 12 12 45 1 -1 232 34 23");
FT_LIST_SORT_EXPECT("12 45 1 -1 232 34 23 87879");
}
void ft_list_sort_test(void)
{
test_name = "ft_list_sort.s";
signaled_suite = false;
ft_list_sort_segfault();
if (!signaled_suite)
ft_list_sort_compare();
}
|