Merge commit '4f4e96655625a0ad8c5fc451c5a3a8dda3bf5456' as 'shared/c-rbtree'
Imported c-rbtree code with command: git subtree add --prefix shared/c-rbtree git@github.com:c-util/c-rbtree.git bf627e0c32241915108f66ad9738444e4d045b45 --squash To update the library use: git subtree pull --prefix shared/c-rbtree git@github.com:c-util/c-rbtree.git master --squash
This commit is contained in:
66
shared/c-rbtree/src/test-misc.c
Normal file
66
shared/c-rbtree/src/test-misc.c
Normal file
@@ -0,0 +1,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 <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;
|
||||
|
||||
assert(t);
|
||||
assert(n);
|
||||
assert(!c_rbnode_is_linked(n));
|
||||
|
||||
i = &t->root;
|
||||
p = NULL;
|
||||
while (*i) {
|
||||
p = *i;
|
||||
if (n < *i) {
|
||||
i = &(*i)->left;
|
||||
} else {
|
||||
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]);
|
||||
}
|
||||
|
||||
assert(!c_rbtree_is_empty(&t1));
|
||||
assert(c_rbtree_is_empty(&t2));
|
||||
|
||||
c_rbtree_move(&t2, &t1);
|
||||
|
||||
assert(c_rbtree_is_empty(&t1));
|
||||
assert(!c_rbtree_is_empty(&t2));
|
||||
|
||||
while (t2.root)
|
||||
c_rbnode_unlink(t2.root);
|
||||
|
||||
assert(c_rbtree_is_empty(&t1));
|
||||
assert(c_rbtree_is_empty(&t2));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_move();
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user