-
Notifications
You must be signed in to change notification settings - Fork 57
/
test_c11.c
182 lines (159 loc) · 3.58 KB
/
test_c11.c
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include "../test.h"
#include <str.h> // MULTIPLE INCLUDES OKAY.
#include <str.h>
#include <str.h>
#include <str.h>
#define P
#define T int
#include <stk.h>
#define P
#define T int
#include <pqu.h>
#define P
#define T int
#include <que.h>
#define P
#define T int
#include <lst.h>
#define P
#define T int
#include <deq.h>
#define P
#define T int
#include <set.h>
#define P
#define T char
#include <vec.h>
#define P
#define T int
#include <vec.h>
#define P
#define T unsigned
#include <vec.h>
#define P
#define T float
#include <vec.h>
#define P
#define T double
#include <vec.h>
typedef struct
{
int x;
int y;
}
point;
#define P
#define T point
#include <vec.h>
#define T str
#include <vec.h>
typedef struct
{
vec_point path;
str name;
}
person;
static person
person_init(size_t path_capacity, const char* first, const char* last)
{
person self;
self.path = vec_point_init();
self.name = str_init(first);
str_append(&self.name, " ");
str_append(&self.name, last);
vec_point_reserve(&self.path, path_capacity);
return self;
}
static void
person_free(person* self)
{
vec_point_free(&self->path);
str_free(&self->name);
}
static person
person_copy(person* self)
{
person copy = {
vec_point_copy(&self->path),
str_copy(&self->name),
};
return copy;
}
#define T person
#include <vec.h>
static int
int_match(int* a, int* b)
{
return *a == *b;
}
static int
int_compare(int* a, int* b)
{
return *a < *b;
}
int
main(void)
{
{
vec_int a = vec_int_init();
vec_int_push_back(&a, 1);
vec_int_push_back(&a, 2);
vec_int_push_back(&a, 3);
vec_int_push_back(&a, 4);
vec_int_free(&a);
}{
const size_t size = 16;
deq_int a = deq_int_init();
for(size_t i = 0; i < size; i++) deq_int_push_back(&a, i);
for(size_t i = 0; i < size; i++) deq_int_push_front(&a, i);
deq_int_insert(&a, 1, 99);
deq_int_sort(&a, int_compare);
deq_int_free(&a);
}{
lst_int a = lst_int_init();
lst_int_push_back(&a, 1);
lst_int_push_back(&a, 2);
lst_int_push_back(&a, 3);
lst_int_push_back(&a, 4);
lst_int_push_back(&a, 5);
lst_int_push_back(&a, 6);
lst_int_push_back(&a, 7);
lst_int_push_back(&a, 8);
lst_int_free(&a);
}{
vec_str b = vec_str_init();
vec_str_push_back(&b, str_init("This"));
vec_str_push_back(&b, str_init("is"));
vec_str_push_back(&b, str_init("a"));
vec_str_push_back(&b, str_init("test"));
vec_str_resize(&b, 512, str_init(""));
vec_str_free(&b);
}{
vec_person c = vec_person_init();
vec_person_push_back(&c, person_init(128, "FIRST", "JONES"));
vec_person_push_back(&c, person_init(256, "LAST", "ALEXA"));
vec_person_push_back(&c, person_init(512, "NAME", "ANOTHER"));
vec_person d = vec_person_copy(&c);
vec_person_free(&c);
vec_person_free(&d);
}{
lst_int a = lst_int_init();
lst_int_push_back(&a, 1);
lst_int_push_back(&a, 1);
lst_int_push_back(&a, 1);
lst_int_push_back(&a, 2);
lst_int_push_back(&a, 3);
lst_int_push_back(&a, 3);
lst_int_push_back(&a, 4);
lst_int_push_back(&a, 6);
lst_int_push_back(&a, 6);
lst_int_push_back(&a, 6);
lst_int_push_back(&a, 6);
lst_int_push_back(&a, 6);
lst_int_push_back(&a, 8);
lst_int_push_back(&a, 8);
lst_int_unique(&a, int_match);
lst_int_free(&a);
}
TEST_PASS(__FILE__);
}