6 #define ARRAY_LEN(a) (sizeof(a)/sizeof(*a))
8 int cmpint(const void *a, const void *b)
10 return *(int*)a - *(int*)b;
15 int ivals[] = {0,1,2,3,4,5,6,7,8,9},
16 ivals2[] = {10,11,12,13,14,15,16,17,18,19};
18 vector *vint = v_new(NULL);
19 assert(v_length(vint) == 0);
20 assert(v_is_empty(vint));
22 for (i = 0; i < ARRAY_LEN(ivals); i++)
23 v_prepend(vint, ivals+i);
24 assert(v_length(vint) == ARRAY_LEN(ivals));
25 assert(*(int*)v_first(vint) == 9);
26 assert(*(int*)v_remove_first(vint) == 9);
27 assert(*(int*)v_remove_first(vint) == 8);
29 assert(*(int*)v_first(vint) == 0);
32 assert(v_length(vint) == 0);
33 for (i = 0; i < ARRAY_LEN(ivals); i++)
34 v_append(vint, ivals+i);
35 assert(v_length(vint) == ARRAY_LEN(ivals));
36 assert(*(int*)v_last(vint) == 9);
37 assert(*(int*)v_remove_last(vint) == 9);
38 assert(*(int*)v_remove_last(vint) == 8);
40 assert(v_find_index(vint, ivals+5, cmpint) == 5);
41 v_insert(vint, 5, ivals2+5);
42 assert(v_find_index(vint, ivals2+5, cmpint) == 5);
44 assert(v_find_index(vint, ivals2+5, cmpint) == 6);
46 assert(v_find_index(vint, ivals2+5, cmpint) == SIZE_MAX);
47 assert(v_find_last_index(vint, ivals2+5, cmpint) == SIZE_MAX);