Subversion Repositories PlanixRsrch.SVN

Rev

Rev 341 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 341 Rev 427
Line 31... Line 31...
31
static int 
31
static int 
32
test_mavl(const char * name,int numvals,int type)
32
test_mavl(const char * name,int numvals,int type)
33
{
33
{
34
	int i;
34
	int i;
35
	int insval;
35
	int insval;
36
	int exists;
36
	int exists,existed;
37
	struct mavl *t;
37
	struct mavl *t;
38
	int rc;
38
	int rc;
39
	float depth, maxdepth;
39
	float depth, maxdepth;
40
 
40
 
41
	(void) printf ("Running insert %s: numvals=%d, type=%d\n"
41
	(void) printf ("Running insert %s: numvals=%d, type=%d\n"
Line 45... Line 45...
45
	/* Create a MAVL object which store object of size of int. */
45
	/* Create a MAVL object which store object of size of int. */
46
	t = mavl_create(cmp, NULL, sizeof(int));
46
	t = mavl_create(cmp, NULL, sizeof(int));
47
	mu_assert (t!=NULL, "mavl_create(%s): %s", name,strerror(errno));
47
	mu_assert (t!=NULL, "mavl_create(%s): %s", name,strerror(errno));
48
 
48
 
49
	srand((unsigned int)time(NULL));
49
	srand((unsigned int)time(NULL));
-
 
50
	existed=0;
50
	for (i = 0; i < numvals; i++) {
51
	for (i = 0; i < numvals; i++) {
51
		switch (type) {
52
		switch (type) {
52
		case 0:
53
		case 0:
53
			insval = rand();
54
			insval = rand();
54
			break;
55
			break;
Line 59... Line 60...
59
			insval = i;
60
			insval = i;
60
			break;
61
			break;
61
 
62
 
62
		};
63
		};
63
		(void)mavl_insert(t, &insval, &exists);
64
		(void)mavl_insert(t, &insval, &exists);
-
 
65
		if (exists)
-
 
66
			existed++;
64
	}
67
	}
65
	rc = mavl_verify(t);
68
	rc = mavl_verify(t);
66
	mu_assert(rc,"Verify (%s)",name);
69
	mu_assert(rc,"Verify (%s)",name);
67
 
70
 
68
	mu_assert(t->count == numvals,
71
	mu_assert(t->count+existed == numvals,
69
			"%s %d != %d",name,t->count, numvals);
72
			"%s %d != %d",name,t->count+existed, numvals);
70
 
73
 
71
	depth = (float)mavl_get_depth(t);
74
	depth = (float)mavl_get_depth(t);
72
	maxdepth = calc_depth(numvals);
75
	maxdepth = calc_depth(numvals);
73
	mu_assert(depth < maxdepth,
76
	mu_assert(depth < maxdepth,
74
			"%s Depth %f >= %f",name,depth,maxdepth);
77
			"%s Depth %f >= %f",name,depth,maxdepth);
Line 80... Line 83...
80
static int 
83
static int 
81
test_mavl_del(const char * name,int numvals,int type)
84
test_mavl_del(const char * name,int numvals,int type)
82
{
85
{
83
	int i;
86
	int i;
84
	int insval,delval;
87
	int insval,delval;
85
	int exists;
88
	int exists,existed;
86
	struct mavl *t;
89
	struct mavl *t;
87
	int rc;
90
	int rc;
88
	float depth, maxdepth;
91
	float depth, maxdepth;
89
	int * vals;
92
	int * vals;
90
 
93
 
Line 98... Line 101...
98
	/* Create a MAVL object which store object of size of int. */
101
	/* Create a MAVL object which store object of size of int. */
99
	t = mavl_create(cmp, NULL, sizeof(int));
102
	t = mavl_create(cmp, NULL, sizeof(int));
100
	mu_assert (t!=NULL, "mavl_create(%s): %s", name,strerror(errno));
103
	mu_assert (t!=NULL, "mavl_create(%s): %s", name,strerror(errno));
101
 
104
 
102
	srand((unsigned int)time(NULL));
105
	srand((unsigned int)time(NULL));
-
 
106
	existed=0;
103
	for (i = 0; i < numvals; i++) {
107
	for (i = 0; i < numvals; i++) {
104
		switch (type) {
108
		switch (type) {
105
		case 0:
109
		case 0:
106
			insval = rand();
110
			insval = rand();
107
			break;
111
			break;
Line 113... Line 117...
113
			break;
117
			break;
114
 
118
 
115
		};
119
		};
116
		vals[i]=insval;
120
		vals[i]=insval;
117
		(void)mavl_insert(t, &insval, &exists);
121
		(void)mavl_insert(t, &insval, &exists);
-
 
122
		if (exists)
-
 
123
			existed++;
-
 
124
 
118
	}
125
	}
119
	rc = mavl_verify(t);
126
	rc = mavl_verify(t);
120
	mu_assert(rc,"Verify (%s)",name);
127
	mu_assert(rc,"Verify (%s)",name);
121
 
128
 
122
	mu_assert(t->count == numvals,
129
	mu_assert(t->count+existed == numvals,
123
			"%s %d != %d",name,t->count, numvals);
130
			"%s %d != %d",name,t->count+existed, numvals);
124
 
131
 
125
	depth = (float)mavl_get_depth(t);
132
	depth = (float)mavl_get_depth(t);
126
	maxdepth = calc_depth(numvals);
133
	maxdepth = calc_depth(numvals);
127
	mu_assert(depth < maxdepth,
134
	mu_assert(depth < maxdepth,
128
			"%s Depth %f >= %f",name,depth,maxdepth);
135
			"%s Depth %f >= %f",name,depth,maxdepth);
Line 135... Line 142...
135
			}
142
			}
136
			fclose(outfile);
143
			fclose(outfile);
137
	}
144
	}
138
*/	for (i=0; i<numvals; i++){
145
*/	for (i=0; i<numvals; i++){
139
		int before_count;
146
		int before_count;
140
		
147
		
141
		delval = vals[i];
148
		delval = vals[i];
142
		before_count = t->count;
149
		before_count = t->count;
143
		(void)mavl_del(t,&delval);
150
		(void)mavl_del(t,&delval);
144
 
151
 
145
		mu_assert(before_count != t->count-1,"%s count %d != %d",
152
		mu_assert(before_count != t->count-1,"%s count %d != %d",
146
				name, before_count,t->count-1);
153
				name, before_count,t->count-1);
147
		
154
		
148
		depth = (float)mavl_get_depth(t);
155
		depth = (float)mavl_get_depth(t);
149
		maxdepth = calc_depth(t->count);
156
		maxdepth = calc_depth(t->count);
150
		
157
		
151
		if (!(depth<=maxdepth)){
158
		if (!(depth<=maxdepth)){
152
		}
159
		}
Line 167... Line 174...
167
static int test0(void)
174
static int test0(void)
168
{
175
{
169
	const char * name = "test0";
176
	const char * name = "test0";
170
	int type = 0;
177
	int type = 0;
171
	int i;
178
	int i;
-
 
179
	
172
	for (i=0; i<1000; i++){
180
	for (i=0; i<1000; i++){
173
		(void)test_mavl(name,i+1,type);
181
		(void)test_mavl(name,i+1,type);
174
	}
182
	}
-
 
183
 
175
	(void)test_mavl(name,1024,type);
184
	(void)test_mavl(name,1024,type);
176
	(void)test_mavl(name,31871,type);
185
	(void)test_mavl(name,31871,type);
177
	(void)test_mavl(name,123456,type);
186
	(void)test_mavl(name,123456,type);
178
	(void)test_mavl(name,1000000,type);
187
	(void)test_mavl(name,1000000,type);
179
	return 1;
188
	return 1;