source: tests/avltree/avl_test.cfa @ d144c26

Last change on this file since d144c26 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
RevLine 
[6e3ae00]1#include "avl.h"
2#include "avl-private.h"
[73abe95]3#include <stdlib.hfa>
[6e3ae00]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
[cb2b15c]17  tree(int, int) * imap = create(-1, (int)0);
[6e3ae00]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 *
[142cf5d]28  tree(int, const char *) * smap = create(-1, "baz");
[6e3ae00]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
[142cf5d]38  // const char* -> const char*
39  int ?<?(const char * a, const char * b) {
40    return strcmp(a, b) < 0;
[6e3ae00]41  }
[142cf5d]42
43  tree(const char *, const char *) * ssmap = create("queso", "cheese");
44  insert(&ssmap, "foo", "bar");
45  insert(&ssmap, "hello", "world");
[6e3ae00]46  assert( height(ssmap) == 2 );
47
[142cf5d]48  printf("%s %s %s\n", *find(ssmap, "hello"), *find(ssmap, "foo"), *find(ssmap, "queso"));
[6e3ae00]49
[142cf5d]50  remove(&ssmap, "foo");
[6e3ae00]51  delete(ssmap);
52}
Note: See TracBrowser for help on using the repository browser.