mirror of
git://projects.qi-hardware.com/wernermisc.git
synced 2024-11-22 14:08:26 +02:00
qpkg: added simple regression test for red-black trees
This commit is contained in:
parent
2787a45c43
commit
b4ff969a24
@ -2,11 +2,14 @@ CFLAGS = -Wall -Wshadow -g -O
|
|||||||
# -O, so that we get data flow analysis, which helps to find more bugs
|
# -O, so that we get data flow analysis, which helps to find more bugs
|
||||||
#LDFLAGS=-pg
|
#LDFLAGS=-pg
|
||||||
|
|
||||||
OBJS = gobble.o id.o prereq.o qpkg.o jrb.o jval.o
|
OBJS = gobble.o id.o prereq.o qpkg.o
|
||||||
|
OBJS_rbtest = rbtest.o jrb.o jval.o
|
||||||
|
|
||||||
all: qpkg
|
all: qpkg rbtest
|
||||||
|
|
||||||
qpkg: $(OBJS)
|
qpkg: $(OBJS)
|
||||||
|
|
||||||
|
rbtest: $(OBJS_rbtest)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJS)
|
rm -f $(OBJS) $(OBJS_rbtest)
|
||||||
|
37
qpkg/rbtest.c
Normal file
37
qpkg/rbtest.c
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "jrb.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int cmp(Jval a, Jval b)
|
||||||
|
{
|
||||||
|
return strcmp(jval_v(a), jval_v(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define INSERT(key, val) \
|
||||||
|
jrb_insert_gen(tree, new_jval_v(key), new_jval_v(val), cmp)
|
||||||
|
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
JRB tree = make_jrb();
|
||||||
|
JRB p;
|
||||||
|
|
||||||
|
INSERT("ab", "have");
|
||||||
|
INSERT("d", "little");
|
||||||
|
INSERT("c", "this");
|
||||||
|
INSERT("b", "passed");
|
||||||
|
INSERT("e", "regression");
|
||||||
|
INSERT("fa", "test");
|
||||||
|
INSERT("aa", "We");
|
||||||
|
INSERT("ff", "!");
|
||||||
|
|
||||||
|
jrb_traverse(p, tree)
|
||||||
|
printf("%s ", (char *) jval_v(p->val));
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user