-
Notifications
You must be signed in to change notification settings - Fork 0
/
delist_test.cc
57 lines (43 loc) · 1.26 KB
/
delist_test.cc
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
56
#include "zda/delist.h"
#include <gtest/gtest.h>
typedef struct int_entry {
int key;
zda_delist_node_t node;
} int_entry_t;
TEST(delist_test, push_back)
{
zda_delist_t dl;
zda_delist_init(&dl);
for (int i = 0; i < 10; ++i) {
auto entry = (int_entry_t *)malloc(sizeof(int_entry_t));
entry->key = i;
zda_delist_push_back(&dl, &entry->node);
}
auto node = zda_delist_front_const(&dl);
int_entry_t const *entry = zda_delist_entry(node, int_entry_t const);
int i = 0;
zda_delist_iterate(&dl)
{
auto entry = zda_delist_entry(pos, int_entry_t);
EXPECT_EQ(i, entry->key);
i++;
}
zda_delist_destroy_inplace(&dl, int_entry_t, free);
}
TEST(delist_test, pop_front)
{
zda_delist_t dl;
zda_delist_init(&dl);
for (int i = 0; i < 10; ++i) {
auto entry = (int_entry_t *)malloc(sizeof(int_entry_t));
entry->key = i;
zda_delist_push_back(&dl, &entry->node);
}
for (int i = 0; i < 10; ++i) {
auto node = zda_delist_pop_front(&dl);
auto entry = zda_delist_entry(node, int_entry_t);
free(entry);
}
EXPECT_TRUE(zda_delist_is_empty(&dl));
zda_delist_destroy_inplace(&dl, int_entry_t, free);
}