-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
89 lines (63 loc) · 2.1 KB
/
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "greatest/greatest.h"
#define SPLAY_TREE_NAME splay_tree_uint32
#define SPLAY_TREE_KEY_TYPE uint32_t
#define SPLAY_TREE_VALUE_TYPE char *
#include "splay_tree.h"
#undef SPLAY_TREE_NAME
#undef SPLAY_TREE_KEY_TYPE
#undef SPLAY_TREE_VALUE_TYPE
TEST test_splay_tree(void) {
splay_tree_uint32 *tree = splay_tree_uint32_new();
char *val1 = "a";
char *val2 = "b";
char *val3 = "c";
splay_tree_uint32_insert(tree, 1, "a");
splay_tree_uint32_insert(tree, 5, "c");
splay_tree_uint32_insert(tree, 3, "b");
splay_tree_uint32_insert(tree, 9, "e");
splay_tree_uint32_insert(tree, 7, "d");
splay_tree_uint32_insert(tree, 11, "f");
char *a = splay_tree_uint32_get(tree, 1);
ASSERT_STR_EQ(a, "a");
char *b = splay_tree_uint32_get(tree, 3);
ASSERT_STR_EQ(b, "b");
char *c = splay_tree_uint32_get(tree, 5);
ASSERT_STR_EQ(c, "c");
char *d = splay_tree_uint32_get(tree, 7);
ASSERT_STR_EQ(d, "d");
char *e = splay_tree_uint32_get(tree, 9);
ASSERT_STR_EQ(e, "e");
a = splay_tree_uint32_delete(tree, 1);
ASSERT_STR_EQ(a, "a");
a = splay_tree_uint32_get(tree, 1);
ASSERT(a == NULL);
b = splay_tree_uint32_delete(tree, 3);
ASSERT_STR_EQ(b, "b");
e = splay_tree_uint32_delete(tree, 9);
ASSERT_STR_EQ(e, "e");
c = splay_tree_uint32_get(tree, 5);
ASSERT_STR_EQ(c, "c");
c = splay_tree_uint32_delete(tree, 5);
ASSERT_STR_EQ(c, "c");
d = splay_tree_uint32_delete(tree, 7);
ASSERT_STR_EQ(d, "d");
d = splay_tree_uint32_get(tree, 7);
ASSERT(d == NULL);
splay_tree_uint32_insert(tree, 7, "d");
d = splay_tree_uint32_get(tree, 7);
splay_tree_uint32_destroy(tree);
PASS();
}
/* Add definitions that need to be in the test runner's main file. */
GREATEST_MAIN_DEFS();
int main(int argc, char **argv) {
GREATEST_MAIN_BEGIN(); /* command-line options, initialization. */
RUN_TEST(test_splay_tree);
GREATEST_MAIN_END(); /* display results */
}