90 |
#define SIZ(a) (sizeof(a)/sizeof(*a)) |
#define SIZ(a) (sizeof(a)/sizeof(*a)) |
91 |
#define CHECK(a) add_array(a,SIZ(a)); print_heap(); check_array(a##s,SIZ(a##s)) |
#define CHECK(a) add_array(a,SIZ(a)); print_heap(); check_array(a##s,SIZ(a##s)) |
92 |
|
|
93 |
int main () |
int main (int argc, char *argv[]) |
94 |
{ |
{ |
95 |
static prio_t arr1[] = {1,10,20,12,14,30,32,16}; |
static prio_t arr1[] = {1,10,20,12,14,30,32,16}; |
96 |
static prio_t arr1s[] = {1,10,12,14,16,20,32}; |
static prio_t arr1s[] = {1,10,12,14,16,20,32}; |
103 |
# define SZ_ARR3 10240 |
# define SZ_ARR3 10240 |
104 |
static prio_t arr3[SZ_ARR3]; |
static prio_t arr3[SZ_ARR3]; |
105 |
static prio_t arr3s[SZ_ARR3]; |
static prio_t arr3s[SZ_ARR3]; |
106 |
int sz_arr3, i, j, removes; |
int sz_arr3, i, j, removes, changes; |
107 |
|
time_t t; |
108 |
|
prio_t pri; |
109 |
|
|
110 |
pq_new (&test_q, 0, test_eq); |
pq_new (&test_q, 0, test_eq); |
111 |
|
|
116 |
|
|
117 |
CHECK(arr2); |
CHECK(arr2); |
118 |
|
|
119 |
srand(time(NULL)); |
/* print seed so we may reproduce a failing test */ |
120 |
|
printf ("Random seed: %d\n", t=(argc>1?atoi(argv[1]):time(NULL))); |
121 |
|
srand(t); |
122 |
sz_arr3 = rand()%(SZ_ARR3/2)+(SZ_ARR3/2); |
sz_arr3 = rand()%(SZ_ARR3/2)+(SZ_ARR3/2); |
123 |
|
printf ("Adding %d nodes.\n", sz_arr3); |
124 |
for (i = 0; i < sz_arr3; i++) |
for (i = 0; i < sz_arr3; i++) |
125 |
arr3[i] = (prio_t)rand(); |
arr3[i] = (prio_t)rand(); |
126 |
|
|
128 |
/*print_heap();*/ |
/*print_heap();*/ |
129 |
|
|
130 |
removes = rand()%sz_arr3; |
removes = rand()%sz_arr3; |
131 |
|
printf ("Removing %d nodes.\n", removes); |
132 |
/*printf ("removing:");*/ |
/*printf ("removing:");*/ |
133 |
for (i = 0; i < removes; i++) { |
for (i = 0; i < removes; i++) { |
134 |
j = rand()%sz_arr3; |
j = rand()%sz_arr3; |
135 |
/*printf (" %d", arr3[j]);*/ |
/*printf (" %d", arr3[j]);*/ |
136 |
test_free(pq_del_func(pq_get(arr3[j],&test_q),&test_q)); |
test_free(pq_del_ptr(pq_get(arr3[j],&test_q),&test_q)); |
137 |
sz_arr3--; |
sz_arr3--; |
138 |
memmove (&arr3[j], &arr3[j+1], sizeof(*arr3)*(sz_arr3-j)); |
memmove (&arr3[j], &arr3[j+1], sizeof(*arr3)*(sz_arr3-j)); |
139 |
} |
} |
144 |
putchar('\n'); |
putchar('\n'); |
145 |
*/ |
*/ |
146 |
|
|
147 |
|
changes = rand()%sz_arr3; |
148 |
|
printf ("Repriorizing %d nodes.\n", changes); |
149 |
|
for (i = 0; i < changes; i++) { |
150 |
|
j = rand()%sz_arr3; |
151 |
|
pri = arr3[j]; |
152 |
|
arr3[j] = (prio_t)rand(); |
153 |
|
pq_chpri_ptr (pq_get(pri,&test_q), arr3[j], &test_q); |
154 |
|
} |
155 |
|
|
156 |
|
/* sort the array */ |
157 |
for (i = 0; i < sz_arr3; i++) { |
for (i = 0; i < sz_arr3; i++) { |
158 |
for (j = 0; j < i && arr3[i] > arr3s[j]; j++) |
for (j = 0; j < i && arr3[i] > arr3s[j]; j++) |
159 |
; |
; |