-
Notifications
You must be signed in to change notification settings - Fork 2
/
insert.c
54 lines (45 loc) · 1.93 KB
/
insert.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
#include "common.h"
int main(void) {
struct StringArray *array = carray_init(array, STRING_ARRAY);
carray_insert(array, 0, "foo", STRING_ARRAY);
assert(strcmp(array->contents[0], "foo") == 0);
assert(array->length == 1);
assert(array->capacity == 5);
carray_insert(array, 0, "bar", STRING_ARRAY);
assert(strcmp(array->contents[0], "bar") == 0);
assert(strcmp(array->contents[1], "foo") == 0);
assert(array->length == 2);
assert(array->capacity == 5);
carray_insert(array, 1, "baz", STRING_ARRAY);
assert(strcmp(array->contents[0], "bar") == 0);
assert(strcmp(array->contents[1], "baz") == 0);
assert(strcmp(array->contents[2], "foo") == 0);
assert(array->length == 3);
assert(array->capacity == 5);
carray_insert(array, 2, "thud", STRING_ARRAY);
assert(strcmp(array->contents[0], "bar") == 0);
assert(strcmp(array->contents[1], "baz") == 0);
assert(strcmp(array->contents[2], "thud") == 0);
assert(strcmp(array->contents[3], "foo") == 0);
assert(array->length == 4);
assert(array->capacity == 5);
carray_insert(array, 1, "spam", STRING_ARRAY);
assert(strcmp(array->contents[0], "bar") == 0);
assert(strcmp(array->contents[1], "spam") == 0);
assert(strcmp(array->contents[2], "baz") == 0);
assert(strcmp(array->contents[3], "thud") == 0);
assert(strcmp(array->contents[4], "foo") == 0);
assert(array->length == 5);
assert(array->capacity == 5);
carray_insert(array, 2, "tuna", STRING_ARRAY);
assert(strcmp(array->contents[0], "bar") == 0);
assert(strcmp(array->contents[1], "spam") == 0);
assert(strcmp(array->contents[2], "tuna") == 0);
assert(strcmp(array->contents[3], "baz") == 0);
assert(strcmp(array->contents[4], "thud") == 0);
assert(strcmp(array->contents[5], "foo") == 0);
assert(array->length == 6);
assert(array->capacity == 10);
carray_free(array, STRING_ARRAY);
return EXIT_SUCCESS;
}