MCPcopy Create free account
hub / github.com/codr7/hacktical-c / vector_tests

Function vector_tests

vector/tests.c:5–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include "vector.h"
4
5void vector_tests() {
6 struct hc_vector v;
7 hc_vector_init(&v, &hc_malloc_default, sizeof(int));
8 const int n = 100;
9
10 for (int i = 0; i < n; i++) {
11 *(int *)hc_vector_push(&v) = i;
12 }
13
14 {
15 int i = 0;
16
17 hc_vector_do(&v, it) {
18 assert(*(int *)it == i++);
19 }
20 }
21
22 assert(v.length == n);
23
24 for (int i = 0; i < n; i++) {
25 assert(*(int *)hc_vector_get(&v, i) == i);
26 }
27
28 assert(*(int *)hc_vector_pop(&v) == n-1);
29 assert(*(int *)hc_vector_peek(&v) == n-2);
30 assert(v.length == n-1);
31
32 for (int i = 0; i < n-1; i++) {
33 assert(*(int *)hc_vector_get(&v, i) == i);
34 }
35
36 assert(hc_vector_delete(&v, 0, 1));
37 assert(v.length == n-2);
38
39 for (int i = 1; i < n-1; i++) {
40 assert(*(int *)hc_vector_get(&v, i-1) == i);
41 }
42
43 (*(int *)hc_vector_insert(&v, 0, 1) = 0);
44 assert(v.length == n-1);
45
46 for (int i = 0; i < n-1; i++) {
47 assert(*(int *)hc_vector_get(&v, i) == i);
48 }
49
50 hc_vector_clear(&v);
51 assert(v.length == 0);
52
53 hc_vector_deinit(&v);
54}

Callers 1

mainFunction · 0.85

Calls 9

hc_vector_initFunction · 0.85
hc_vector_pushFunction · 0.85
hc_vector_getFunction · 0.85
hc_vector_popFunction · 0.85
hc_vector_peekFunction · 0.85
hc_vector_deleteFunction · 0.85
hc_vector_insertFunction · 0.85
hc_vector_clearFunction · 0.85
hc_vector_deinitFunction · 0.85

Tested by

no test coverage detected