76,19 → 76,104 |
return 1; |
} |
|
static int |
test_mavl_del(const char * name,int numvals,int type) |
{ |
int i; |
int insval,delval; |
int exists; |
struct mavl *t; |
int rc; |
float depth, maxdepth; |
int * vals; |
|
(void) printf ("Running insert and del %s: numvals=%d, type=%d\n" |
,name, numvals,type); |
|
vals = malloc(sizeof(int)*(size_t)numvals); |
mu_assert(vals != NULL,"%s - allocate vals", |
name); |
|
/* Create a MAVL object which store object of size of int. */ |
t = mavl_create(cmp, NULL, sizeof(int)); |
mu_assert (t!=NULL, "mavl_create(%s): %s", name,strerror(errno)); |
|
srand((unsigned int)time(NULL)); |
for (i = 0; i < numvals; i++) { |
switch (type) { |
case 0: |
insval = rand(); |
break; |
case -1: |
insval = numvals-i; |
break; |
default: |
insval = i; |
break; |
|
}; |
vals[i]=insval; |
(void)mavl_insert(t, &insval, &exists); |
} |
rc = mavl_verify(t); |
mu_assert(rc,"Verify (%s)",name); |
|
mu_assert(t->count == numvals, |
"%s %d != %d",name,t->count, numvals); |
|
depth = (float)mavl_get_depth(t); |
maxdepth = calc_depth(numvals); |
mu_assert(depth < maxdepth, |
"%s Depth %f >= %f",name,depth,maxdepth); |
|
{ FILE * outfile; |
int i1; |
outfile = fopen("error.dat","wt"); |
for (i1=0; i1<numvals; i1++){ |
fprintf(outfile, "%d ",vals[i1]); |
} |
fclose(outfile); |
} |
for (i=0; i<numvals; i++){ |
int before_count; |
|
delval = vals[i]; |
before_count = t->count; |
mavl_del(t,&delval); |
|
mu_assert(before_count != t->count-1,"%s count %d != %d", |
name, before_count,t->count-1); |
|
depth = (float)mavl_get_depth(t); |
maxdepth = calc_depth(t->count); |
|
if (!(depth<=maxdepth)){ |
} |
|
mu_assert(depth <= maxdepth, |
"%s Del Depth %f >= %f (N: %d)",name,depth,maxdepth,t->count); |
|
} |
mavl_destroy(t); |
return 1; |
} |
|
|
|
|
|
static int test0(void) |
{ |
const char * name = "test0"; |
int type = 0; |
(void)test_mavl(name,1,type); |
(void)test_mavl(name,2,type); |
(void)test_mavl(name,3,type); |
(void)test_mavl(name,10,type); |
int i; |
for (i=0; i<10000; i++){ |
(void)test_mavl(name,i+1,type); |
} |
(void)test_mavl(name,1024,type); |
(void)test_mavl(name,31871,type); |
(void)test_mavl(name,123456,type); |
(void)test_mavl(name,1000000,type); |
(void)test_mavl(name,5000000,type); |
return 1; |
} |
|
104,7 → 189,6 |
(void)test_mavl(name,31871,type); |
(void)test_mavl(name,123456,type); |
(void)test_mavl(name,1000000,type); |
(void)test_mavl(name,5000000,type); |
return 1; |
} |
|
120,18 → 204,32 |
(void)test_mavl(name,31871,type); |
(void)test_mavl(name,123456,type); |
(void)test_mavl(name,1000000,type); |
(void)test_mavl(name,5000000,type); |
return 1; |
} |
|
|
static int test0_del(void) |
{ |
int i; |
const char * name = "test0_del"; |
int type = 0; |
(void)test_mavl_del(name,1,type); |
(void)test_mavl_del(name,2,type); |
(void)test_mavl_del(name,3,type); |
for (i=0; i<100000; i++) |
(void)test_mavl_del(name,40,type); |
/* (void)test_mavl_del(name,12701,type);*/ |
return 1; |
} |
int |
main(void) |
{ |
printf("First: %f\n",calc_depth(1)); |
|
mutests tf = { |
test0, |
test0_del, |
/* test0, |
test1, |
test2, |
test2,*/ |
NULL |
}; |
return mutests_run(tf); |