Date:2010-11-19 23:33:05 (8 years 9 months ago)
Author:Werner Almesberger
Commit:b4ff969a24794bb122cb92789571e6a69f2c691b
Message:qpkg: added simple regression test for red-black trees

Files: qpkg/Makefile (1 diff)
qpkg/rbtest.c (1 diff)

Change Details

qpkg/Makefile
22# -O, so that we get data flow analysis, which helps to find more bugs
33#LDFLAGS=-pg
44
5OBJS = gobble.o id.o prereq.o qpkg.o jrb.o jval.o
5OBJS = gobble.o id.o prereq.o qpkg.o
6OBJS_rbtest = rbtest.o jrb.o jval.o
67
7all: qpkg
8all: qpkg rbtest
89
910qpkg: $(OBJS)
1011
12rbtest: $(OBJS_rbtest)
13
1114clean:
12    rm -f $(OBJS)
15    rm -f $(OBJS) $(OBJS_rbtest)
qpkg/rbtest.c
1#include <stdio.h>
2#include <string.h>
3
4#include "jrb.h"
5
6
7
8static int cmp(Jval a, Jval b)
9{
10    return strcmp(jval_v(a), jval_v(b));
11}
12
13
14#define INSERT(key, val) \
15    jrb_insert_gen(tree, new_jval_v(key), new_jval_v(val), cmp)
16
17
18int main(void)
19{
20    JRB tree = make_jrb();
21    JRB p;
22
23    INSERT("ab", "have");
24    INSERT("d", "little");
25    INSERT("c", "this");
26    INSERT("b", "passed");
27    INSERT("e", "regression");
28    INSERT("fa", "test");
29    INSERT("aa", "We");
30    INSERT("ff", "!");
31
32    jrb_traverse(p, tree)
33        printf("%s ", (char *) jval_v(p->val));
34    printf("\n");
35
36    return 0;
37}

Archive Download the corresponding diff file

Branches:
master



interactive