blob: ac2717cdc0104b5da9c2116f5c3deda479f50e9b (
plain)
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
|
/*
* Tests for Miscellaneous Tree Operations
* This test contains all of the minor tests that did not fit anywhere else.
*/
#undef NDEBUG
#include <assert.h>
#include <c-stdaux.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "c-rbtree.h"
#include "c-rbtree-private.h"
static void insert(CRBTree *t, CRBNode *n) {
CRBNode **i, *p;
c_assert(t);
c_assert(n);
c_assert(!c_rbnode_is_linked(n));
i = &t->root;
p = NULL;
while (*i) {
p = *i;
if (n < *i) {
i = &(*i)->left;
} else {
c_assert(n > *i);
i = &(*i)->right;
}
}
c_rbtree_add(t, p, i, n);
}
static void test_move(void) {
CRBTree t1 = C_RBTREE_INIT, t2 = C_RBTREE_INIT;
CRBNode n[128];
unsigned int i;
for (i = 0; i < sizeof(n) / sizeof(*n); ++i) {
n[i] = (CRBNode)C_RBNODE_INIT(n[i]);
insert(&t1, &n[i]);
}
c_assert(!c_rbtree_is_empty(&t1));
c_assert(c_rbtree_is_empty(&t2));
c_rbtree_move(&t2, &t1);
c_assert(c_rbtree_is_empty(&t1));
c_assert(!c_rbtree_is_empty(&t2));
while (t2.root)
c_rbnode_unlink(t2.root);
c_assert(c_rbtree_is_empty(&t1));
c_assert(c_rbtree_is_empty(&t2));
}
int main(int argc, char **argv) {
test_move();
return 0;
}
|