source: src/tests/avltree/avl_test.c@ 807d8c3

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox 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 807d8c3 was db67b11, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Fix avl_test to use stdlib include instead of 'delete' forward declaration

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include "avl.h"
2#include "avl-private.h"
3#include <stdlib>
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.