1*7f2fe78bSCy Schubert /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2*7f2fe78bSCy Schubert #include <stdio.h>
3*7f2fe78bSCy Schubert #include <stdarg.h>
4*7f2fe78bSCy Schubert #include <assert.h>
5*7f2fe78bSCy Schubert
6*7f2fe78bSCy Schubert typedef struct { int a, b; } elt;
eltcp(elt * dest,elt src)7*7f2fe78bSCy Schubert static int eltcp(elt *dest, elt src)
8*7f2fe78bSCy Schubert {
9*7f2fe78bSCy Schubert *dest = src;
10*7f2fe78bSCy Schubert return 0;
11*7f2fe78bSCy Schubert }
eltcmp(elt left,elt right)12*7f2fe78bSCy Schubert static int eltcmp(elt left, elt right)
13*7f2fe78bSCy Schubert {
14*7f2fe78bSCy Schubert if (left.a < right.a)
15*7f2fe78bSCy Schubert return -1;
16*7f2fe78bSCy Schubert if (left.a > right.a)
17*7f2fe78bSCy Schubert return 1;
18*7f2fe78bSCy Schubert if (left.b < right.b)
19*7f2fe78bSCy Schubert return -1;
20*7f2fe78bSCy Schubert if (left.b > right.b)
21*7f2fe78bSCy Schubert return 1;
22*7f2fe78bSCy Schubert return 0;
23*7f2fe78bSCy Schubert }
eltprt(elt v,FILE * f)24*7f2fe78bSCy Schubert static void eltprt(elt v, FILE *f)
25*7f2fe78bSCy Schubert {
26*7f2fe78bSCy Schubert fprintf(f, "{%d,%d}", v.a, v.b);
27*7f2fe78bSCy Schubert }
intcmp(int left,int right)28*7f2fe78bSCy Schubert static int intcmp(int left, int right)
29*7f2fe78bSCy Schubert {
30*7f2fe78bSCy Schubert if (left < right)
31*7f2fe78bSCy Schubert return -1;
32*7f2fe78bSCy Schubert if (left > right)
33*7f2fe78bSCy Schubert return 1;
34*7f2fe78bSCy Schubert return 0;
35*7f2fe78bSCy Schubert }
intprt(int v,FILE * f)36*7f2fe78bSCy Schubert static void intprt(int v, FILE *f)
37*7f2fe78bSCy Schubert {
38*7f2fe78bSCy Schubert fprintf(f, "%d", v);
39*7f2fe78bSCy Schubert }
40*7f2fe78bSCy Schubert
41*7f2fe78bSCy Schubert #include "maptest.h"
42*7f2fe78bSCy Schubert
43*7f2fe78bSCy Schubert foo foo1;
44*7f2fe78bSCy Schubert
main()45*7f2fe78bSCy Schubert int main ()
46*7f2fe78bSCy Schubert {
47*7f2fe78bSCy Schubert elt v1 = { 1, 2 }, v2 = { 3, 4 };
48*7f2fe78bSCy Schubert const elt *vp;
49*7f2fe78bSCy Schubert const int *ip;
50*7f2fe78bSCy Schubert
51*7f2fe78bSCy Schubert assert(0 == foo_init(&foo1));
52*7f2fe78bSCy Schubert vp = foo_findleft(&foo1, 47);
53*7f2fe78bSCy Schubert assert(vp == NULL);
54*7f2fe78bSCy Schubert assert(0 == foo_add(&foo1, 47, v1));
55*7f2fe78bSCy Schubert vp = foo_findleft(&foo1, 47);
56*7f2fe78bSCy Schubert assert(vp != NULL);
57*7f2fe78bSCy Schubert assert(0 == eltcmp(*vp, v1));
58*7f2fe78bSCy Schubert vp = foo_findleft(&foo1, 3);
59*7f2fe78bSCy Schubert assert(vp == NULL);
60*7f2fe78bSCy Schubert assert(0 == foo_add(&foo1, 93, v2));
61*7f2fe78bSCy Schubert ip = foo_findright(&foo1, v1);
62*7f2fe78bSCy Schubert assert(ip != NULL);
63*7f2fe78bSCy Schubert assert(*ip == 47);
64*7f2fe78bSCy Schubert printf("Map content: ");
65*7f2fe78bSCy Schubert foo_printmap(&foo1, stdout);
66*7f2fe78bSCy Schubert printf("\n");
67*7f2fe78bSCy Schubert return 0;
68*7f2fe78bSCy Schubert }
69