From b4ff969a24794bb122cb92789571e6a69f2c691b Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 19 Nov 2010 19:33:05 -0300 Subject: [PATCH] qpkg: added simple regression test for red-black trees --- qpkg/Makefile | 9 ++++++--- qpkg/rbtest.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 qpkg/rbtest.c diff --git a/qpkg/Makefile b/qpkg/Makefile index b08ed11..9a3c2e2 100644 --- a/qpkg/Makefile +++ b/qpkg/Makefile @@ -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) diff --git a/qpkg/rbtest.c b/qpkg/rbtest.c new file mode 100644 index 0000000..cf1cb58 --- /dev/null +++ b/qpkg/rbtest.c @@ -0,0 +1,37 @@ +#include +#include + +#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; +}