1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-12-22 06:11:09 +02:00

qpkg: added simple regression test for red-black trees

This commit is contained in:
Werner Almesberger 2010-11-19 19:33:05 -03:00
parent 2787a45c43
commit b4ff969a24
2 changed files with 43 additions and 3 deletions

View File

@ -2,11 +2,14 @@ CFLAGS = -Wall -Wshadow -g -O
# -O, so that we get data flow analysis, which helps to find more bugs
#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)
rbtest: $(OBJS_rbtest)
clean:
rm -f $(OBJS)
rm -f $(OBJS) $(OBJS_rbtest)

37
qpkg/rbtest.c Normal file
View 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;
}