source: tests/avltree/avl_test.cfa @ 9d5eacb

Last change on this file since 9d5eacb was 107b01a, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Several changes to the makefiles

  • change .c tests to .cfa
  • add require for libtool in configure
  • libtoolize to fix some warnings
  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include "avl.h"
2#include "avl-private.h"
3#include <stdlib.hfa>
4
5extern "C" {
6  int strcmp(const char *, const char *);
7}
8
9int main(){
10  // operations:
11  // find(tree(K, V) *, K)
12  // int empty(tree(K, V) *);
13  // tree(K, V) * insert(tree(K, V) *, K, V);
14  // int remove(tree(K, V) **, K);
15
16  // int -> int
17  tree(int, int) * imap = create(-1, (int)0);
18  insert(&imap, 12, 13);
19  insert(&imap, 2, 3);
20  assert( height(imap) == 2 );
21
22  printf("%d %d %d\n", *find(imap, 2), *find(imap, 12), *find(imap, -1));
23
24  remove(&imap, -1);
25  delete(imap);
26
27  // int -> char *
28  tree(int, const char *) * smap = create(-1, "baz");
29  insert(&smap, 12, "bar");
30  insert(&smap, 2, "foo");
31  assert( height(smap) == 2 );
32
33  printf("%s %s %s\n", *find(smap, 2), *find(smap, 12), *find(smap, -1));
34
35  remove(&smap, -2);
36  delete(smap);
37
38  // const char* -> const char*
39  int ?<?(const char * a, const char * b) {
40    return strcmp(a, b) < 0;
41  }
42
43  tree(const char *, const char *) * ssmap = create("queso", "cheese");
44  insert(&ssmap, "foo", "bar");
45  insert(&ssmap, "hello", "world");
46  assert( height(ssmap) == 2 );
47
48  printf("%s %s %s\n", *find(ssmap, "hello"), *find(ssmap, "foo"), *find(ssmap, "queso"));
49
50  remove(&ssmap, "foo");
51  delete(ssmap);
52}
Note: See TracBrowser for help on using the repository browser.