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