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