ctest.c 2.01 KB
Newer Older
dcw's avatar
dcw committed
1
#include <stdio.h>
2
#include <mem.h>
3
#include "cx.h"
dcw's avatar
dcw committed
4
5
6
7
8


intlist int1, int2, int3;


9
void test_intlist( void )
dcw's avatar
dcw committed
10
11
{
	printf( "intlists:\n" );
dcw's avatar
dcw committed
12
13
14
15
16
17
	printf( "\n int1: len %d, ", length(int1) );
	print_intlist( stdout, int1 );
	printf( "\n int2: len %d, ", length(int2) );
	print_intlist( stdout, int2 );
	printf( "\n int3: len %d, ", length(int3) );
	print_intlist( stdout, int3 );
dcw's avatar
dcw committed
18
19
20
21
	printf( "\n\n" );
}


22
void test_illist( void )
dcw's avatar
dcw committed
23
24
25
{
	illist  il1, il2, il3, il4;

dcw's avatar
dcw committed
26
	il1 = illist_nil();
27
28
29
	il2 = illist_cons( int1, illist_nil() );
	il3 = illist_cons( int2, illist_cons( int1, illist_nil() ) );
	il4 = illist_cons( int3, illist_cons( int2, illist_cons( int1, illist_nil() ) ) );
dcw's avatar
dcw committed
30
31

	printf( "illists:\n" );
32
33
34
35
	printf( "\n il1: len %d, ", lengthil(il1) ); print_illist( stdout, il1 );
	printf( "\n il2: len %d, ", lengthil(il2) ); print_illist( stdout, il2 );
	printf( "\n il3: len %d, ", lengthil(il3) ); print_illist( stdout, il3 );
	printf( "\n il4: len %d, ", lengthil(il4) ); print_illist( stdout, il4 );
dcw's avatar
dcw committed
36
	printf( "\n\n" );
37
38
39
40
41

	free_illist( il1 );
	free_illist( il2 );
	free_illist( il3 );
	free_illist( il4 );
dcw's avatar
dcw committed
42
43
44
}


45
void test_idtree( void )
dcw's avatar
dcw committed
46
{
47
	idtree	id1, id2, id3, id4, id5;
dcw's avatar
dcw committed
48

49
50
	id1 = idtree_leaf( "hello", int1 );
	id2 = idtree_leaf( "there", int2 );
51
52
53
	id3 = idtree_leaf( "wotcher", int3 );
	id4 = idtree_node( id1, id2 );
	id5 = idtree_node( id3, id4 );
dcw's avatar
dcw committed
54
55

	printf( "idtrees:\n" );
dcw's avatar
dcw committed
56
57
58
59
60
	printf( "\n id1: " ); print_idtree( stdout, id1 );
	printf( "\n id2: " ); print_idtree( stdout, id2 );
	printf( "\n id3: " ); print_idtree( stdout, id3 );
	printf( "\n id4: " ); print_idtree( stdout, id4 );
	printf( "\n id5: " ); print_idtree( stdout, id5 );
dcw's avatar
dcw committed
61
	printf( "\n\n" );
62
63
64
65
66
67

	//free_idtree( id1 );
	//free_idtree( id2 );
	//free_idtree( id3 );
	//free_idtree( id4 );
	free_idtree( id5 );
dcw's avatar
dcw committed
68
69
70
}


71
int main( void )
dcw's avatar
dcw committed
72
{
dcw's avatar
dcw committed
73
	init_cx();
74
75
76
77
78

	int1 = intlist_nil();
	int2 = intlist_cons( 11, intlist_nil() );
	int3 = intlist_cons( 20, intlist_cons( 11, intlist_nil() ) );

dcw's avatar
dcw committed
79
	test_intlist();
80

dcw's avatar
dcw committed
81
	test_illist();
82

dcw's avatar
dcw committed
83
	test_idtree();
84
85
86
87
88
89

	free_intlist( int1 );
	free_intlist( int2 );
	free_intlist( int3 );

	exit(0);
90
	return 0;
dcw's avatar
dcw committed
91
}