summaryrefslogtreecommitdiff
path: root/tests/vec.c
blob: a84096c101af6e77bf05568d8f9024f05997f32e (plain) (blame)
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
#include <assert.h>

#define VEC_TYPE int
#define VEC_NAME ints
#include <conts/vec.h>

int main()
{
	struct ints ints = ints_create(0);
	for (int i = 0; i < 1000000; ++i) {
		ints_append(&ints, i);
	}
	assert(ints_len(&ints) == 1000000);

	for (int i = 0; i < 1000000; ++i) {
		int *v = ints_at(&ints, i);
		assert(v && *v == i);
	}

	int i = 0;
	foreach(ints, iter, &ints) {
		assert(iter && *iter == i);
		i++;
	}

	for (int i = 1000000 - 1; i >= 0; --i) {
		ints_remove(&ints, i);
	}
	assert(ints_len(&ints) == 0);

	ints_destroy(&ints);
}