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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#include <test/test.h>
#include "util.h"
LILY_FILE_BEGIN(util_suite)
LILY_TEST("expand NULL array")
{
size_t count = 0;
int *array = NULL;
int *first = kai_expand_array((void**) &array, &count, sizeof(int));
CHECK_NEQ(first, NULL, "%p");
CHECK_NEQ(array, NULL, "%p");
CHECK_EQ(first, array, "%p");
CHECK_EQ(count, 1, "%d");
int *second = kai_expand_array((void**) &array, &count, sizeof(int));
CHECK_NEQ(second, NULL, "%p");
CHECK_EQ(second, array+1, "%p");
CHECK_EQ(count, 2, "%d");
free(array);
}
#include LILY_PUSH_TEST()
struct test100 {
int value;
const char *str;
};
LILY_TEST("expand array 100 times")
{
size_t count = 0;
struct test100 *array = NULL;
const char *str = "hello, world!";
for (int i=0; i<100; i++) {
struct test100 *element = kai_expand_array((void**) &array, &count, sizeof(struct test100));
element->value = i;
element->str = str;
}
CHECK_EQ(count, 100, "%ul");
for (int i=0; i<100; i++) {
CHECK_EQ(array[i].value, i, "%d");
CHECK_EQ(array[i].str, str, "%p");
}
free(array);
}
#include LILY_PUSH_TEST()
LILY_TEST("convert string to real array")
{
const char *str = "0 0.5 1 1.5 2";
ka_real_t array[5];
int conv = kai_text_to_reals(array, str, 5);
CHECK_EQ(conv, 5, "%d");
CHECK_EQF(array[0], 0.0f, "%f");
CHECK_EQF(array[1], 0.5f, "%f");
CHECK_EQF(array[2], 1.0f, "%f");
CHECK_EQF(array[3], 1.5f, "%f");
CHECK_EQF(array[4], 2.0f, "%f");
}
#include LILY_PUSH_TEST()
LILY_TEST("convert string to real array with fewer conversions than expected")
{
const char *str = "0 0.5 1";
ka_real_t array[5];
int conv = kai_text_to_reals(array, str, 5);
CHECK_EQ(conv, 3, "%d");
CHECK_EQF(array[0], 0.0f, "%f");
CHECK_EQF(array[1], 0.5f, "%f");
CHECK_EQF(array[2], 1.0f, "%f");
CHECK_EQF(array[3], 0.0f, "%f");
CHECK_EQF(array[4], 0.0f, "%f");
}
#include LILY_PUSH_TEST()
#define LILY_FILE_END
#include LILY_REGISTER_TESTS()
|