-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharray_test.c
More file actions
41 lines (35 loc) · 899 Bytes
/
Copy patharray_test.c
File metadata and controls
41 lines (35 loc) · 899 Bytes
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
#include "array.h"
#include "test.h"
#include <stdlib.h>
int main(void) {
float *ptr = NULL;
int len = 0;
// Push values one at a time.
for (int i = 0; i < 42; i++) {
ptr = push_back(ptr, len);
ptr[len++] = (float)i;
}
for (int i = 0; i < 42; i++) {
expect(equiv(ptr[i], (float)i));
}
// Drop values one at a time.
for (int i = 42; i --> 0;) {
expect(equiv(ptr[--len], (float)i));
ptr = drop_back(ptr, len);
}
expect(ptr == NULL);
expect(len == 0);
// Drop everything at once.
for (int i = 0; i < 42; i++) {
ptr = push_back(ptr, len);
ptr[len++] = (float)i;
}
ptr = drop_back(ptr, len=0);
expect(ptr == NULL);
// Let's see how big we can go.
len = 0x40000000;
ptr = push_back(ptr, len);
ptr[len++] = 42.0f;
drop_back(ptr, len=0);
return 0;
}