-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_test.c
55 lines (47 loc) · 1.22 KB
/
list_test.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
55
#include <string.h>
#include "unit_test.h"
#include "list.h"
#define NODES_NUM 1024
UNIT_START
node_t nodes[NODES_NUM];
int data[NODES_NUM];
list_t list;
node_t *node_buf;
int i;
memset(&list, 0, sizeof(list_t));
memset(nodes, 0, sizeof(node_t) * NODES_NUM);
TEST_START("list_push_front()");
for (i = 0; i < NODES_NUM; ++i) {
data[i] = i;
nodes[i].data = data + i;
list_push_front(&list, nodes + i);
CHECK_EQUAL((int)list.size, i + 1);
}
TEST_END;
TEST_START("list_pop_back()");
for (i = 0; i < NODES_NUM; ++i) {
node_buf = list_pop_back(&list);
CHECK_EQUAL(*(int*)node_buf->data, i);
CHECK_EQUAL((int)list.size, NODES_NUM - (i + 1));
}
CHECK_IF(!list_pop_back(&list));
CHECK_IF(!list_pop_front(&list));
TEST_END;
TEST_START("list_push_back)");
for (i = 0; i < NODES_NUM; ++i) {
data[i] = i;
nodes[i].data = data + i;
list_push_back(&list, nodes + i);
CHECK_EQUAL((int)list.size, i + 1);
}
TEST_END;
TEST_START("list_pop_front()");
for (i = 0; i < NODES_NUM; ++i) {
node_buf = list_pop_front(&list);
CHECK_EQUAL(*(int*)node_buf->data, i);
CHECK_EQUAL((int)list.size, NODES_NUM - (i + 1));
}
CHECK_IF(!list_pop_front(&list));
CHECK_IF(!list_pop_back(&list));
TEST_END;
UNIT_END