source: src/tests/avltree/avl_test.c@ 8b52686

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 8b52686 was 3dcd347a, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

moved some more tests to new test folder

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include "avl.h"
2#include "avl-private.h"
3
4extern "C" {
5 int printf(const char *, ...);
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, 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, 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 // char* -> char*
39 int ?<?(char *a, char *b) {
40 return strcmp(a,b) < 0;
41 }
42 tree(char *, char *) * ssmap = create("queso", "cheese");
43 insert(&ssmap, "foo", "bar");
44 insert(&ssmap, "hello", "world");
45 assert( height(ssmap) == 2 );
46
47 printf("%s %s %s\n", *find(ssmap, "hello"), *find(ssmap, "foo"), *find(ssmap, "queso"));
48
49 remove(&ssmap, "foo");
50 delete(ssmap);
51}
Note: See TracBrowser for help on using the repository browser.