-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy patharray.c
More file actions
50 lines (41 loc) · 1.23 KB
/
array.c
File metadata and controls
50 lines (41 loc) · 1.23 KB
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
#include "bdd-for-c.h"
#include "array.h"
spec("array") {
static _bdd_array* arr;
before_each() {
arr = _bdd_array_create();
}
after_each() {
_bdd_array_free(arr);
}
it("should create with a default capacity of 4") {
check(arr->values != NULL);
check(arr->capacity == 4);
check(arr->size == 0);
}
it("should allow to push values to the end") {
_bdd_array_push(arr, "foo");
}
it("should allow to access the last item") {
_bdd_array_push(arr, "foo");
char* last = _bdd_array_last(arr);
check(strcmp(last, "foo") == 0);
}
it("should allow to pop an array of the end") {
_bdd_array_push(arr, "foo");
_bdd_array_push(arr, "bar");
char* popped = _bdd_array_pop(arr);
check(strcmp(popped, "bar") == 0);
char* last = _bdd_array_last(arr);
check(strcmp(last, "foo") == 0);
}
it("should increase the capacity to twice the previous one") {
_bdd_array_push(arr, "1");
_bdd_array_push(arr, "2");
_bdd_array_push(arr, "3");
_bdd_array_push(arr, "4");
_bdd_array_push(arr, "5");
check(arr->capacity == 8);
check(arr->size == 5);
}
}