CR2RE Pipeline Reference Manual 1.6.7
hdrl_cat_utils_sort-test.c
1/*
2 * This file is part of the HDRL
3 * Copyright (C) 2017 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <cpl_test.h>
21
22#include "../hdrl_cat_utils_sort.h"
23
24#include "hdrl_random.h"
25#include "hdrl_types.h"
26
27
28/* Number of elements of arrays in the random test */
29#define N 10000
30
31/* The different methods to fill with numbers the random arrays */
32#define RANDOM_INIT 0
33#define RANDOM_UNIFORM_DOBULE 1
34#define RANDOM_NORMAL 2
35#define RANDOM_POISSON 3
36#define RANDOM_END 4
37
38
39/* Comparing function with ascending sort direction */
40int comparation_asc(const void * a, const void * b)
41{
42 const double a_d = *(const double *)a;
43 const double b_d = *(const double *)b;
44
45 return a_d < b_d ? -1 : (a_d > b_d ? 1 : 0);
46}
47
48/* Compraring Function with descending sort direction */
49int comparation_des(const void * a, const void * b)
50{
51 const double a_d = *(const double *)a;
52 const double b_d = *(const double *)b;
53
54 return a_d > b_d ? -1 : (a_d < b_d ? 1 : 0);
55}
56
57void test_sort(double *a, double *b, cpl_vector *c_vec, cpl_size random_type, cpl_sort_direction dir) {
58
59 /* Initialize the seed for to have repeteability with the results
60 * and to be sure of test the same numbers */
61 double rd;
62 hdrl_random_state *state = hdrl_random_state_new(1, NULL);
63
64 /* Depending of the ramdom_type fill the arrays with different kind of random numbers */
65 for (cpl_size i = 0; i < N; i++) {
66
67 switch(random_type) {
68 case RANDOM_UNIFORM_DOBULE : rd = hdrl_random_uniform_double(state, 10., 20.); break;
69 case RANDOM_NORMAL : rd = hdrl_random_normal(state, 3.5, 1.5); break;
70 case RANDOM_POISSON : rd = hdrl_random_poisson(state, 100.); break;
71 default : exit(1);
72 }
73
74 a[i] = rd;
75 b[i] = rd;
76 cpl_vector_set(c_vec, i, rd);
77 }
78 hdrl_random_state_delete(state);
79
80 /* Call the functions depending of the ascending/descending sort direction */
81 if(dir == CPL_SORT_ASCENDING) {
82 qsort(a, N, sizeof(*a), comparation_asc);
83 } else {
84 qsort(a, N, sizeof(*a), comparation_des);
85 }
86 sort_array(b, N, sizeof(*b), HDRL_SORT_DOUBLE, dir);
87 cpl_vector_sort(c_vec, dir);
88
89 /* Check the results */
90 for (cpl_size i = 0; i < N; i++) {
91 cpl_test_eq(a[i], b[i]);
92 cpl_test_eq(a[i], cpl_vector_get(c_vec, i));
93 cpl_test_eq(b[i], cpl_vector_get(c_vec, i));
94 }
95}
96
97void test_cmp_sort_func(cpl_sort_direction dir)
98{
99 double *a = cpl_malloc(N * sizeof(double));
100 double *b = cpl_malloc(N * sizeof(double));
101 double *c = cpl_malloc(N * sizeof(double));
102 cpl_vector *c_vec = cpl_vector_wrap(N, c);
103
104 /* Sort vector with diferent fill random numbers */
105 for(cpl_size i = RANDOM_INIT + 1; i < RANDOM_END; i++) {
106 test_sort(a, b, c_vec, i, dir);
107 }
108
109 cpl_vector_unwrap(c_vec);
110 cpl_free(a);
111 cpl_free(b);
112 cpl_free(c);
113}
114
115void test_sort_arrays_random(void)
116{
117 double *a_asc = cpl_malloc(N * sizeof(double));
118 double *a_des = cpl_malloc(N * sizeof(double));
119 double *a1 = cpl_malloc(N * sizeof(double));
120 double *a2 = cpl_malloc(N * sizeof(double));
121 double *a3 = cpl_malloc(N * sizeof(double));
122 double *a4 = cpl_malloc(N * sizeof(double));
123 double *a6 = cpl_malloc(N * sizeof(double));
124 double *a7 = cpl_malloc(N * sizeof(double));
125 double *a8 = cpl_malloc(N * sizeof(double));
126 double *a9 = cpl_malloc(N * sizeof(double));
127
128 int *b_asc = cpl_malloc(N * sizeof(int));
129 int *b_des = cpl_malloc(N * sizeof(int));
130 int *b1 = cpl_malloc(N * sizeof(int));
131 int *b6 = cpl_malloc(N * sizeof(int));
132
133 double *c_asc = cpl_malloc(N * sizeof(double));
134 double *c_des = cpl_malloc(N * sizeof(double));
135 double *c2 = cpl_malloc(N * sizeof(double));
136 double *c7 = cpl_malloc(N * sizeof(double));
137
138 cpl_size *d_asc = cpl_malloc(N * sizeof(cpl_size));
139 cpl_size *d_des = cpl_malloc(N * sizeof(cpl_size));
140 cpl_size *d3 = cpl_malloc(N * sizeof(cpl_size));
141 cpl_size *d8 = cpl_malloc(N * sizeof(cpl_size));
142
143 hdrl_value *e_asc = cpl_malloc(N * sizeof(hdrl_value));
144 hdrl_value *e_des = cpl_malloc(N * sizeof(hdrl_value));
145 hdrl_value *e4 = cpl_malloc(N * sizeof(hdrl_value));
146 hdrl_value *e9 = cpl_malloc(N * sizeof(hdrl_value));
147
148
149 /* Fill arrays with random values */
150 hdrl_random_state *state = hdrl_random_state_new(1, NULL);
151 for (cpl_size i = 0; i < N; i++) {
152
153 a_asc[i] = hdrl_random_normal(state, 5.5, 0.5);
154 a1[i] = a_asc[i];
155 a2[i] = a_asc[i];
156 a3[i] = a_asc[i];
157 a4[i] = a_asc[i];
158 a_des[i] = a_asc[i];
159 a6[i] = a_des[i];
160 a7[i] = a_des[i];
161 a8[i] = a_des[i];
162 a9[i] = a_des[i];
163
164 b_asc[i] = hdrl_random_poisson(state, 100.);
165 b1[i] = b_asc[i];
166 b_des[i] = b_asc[i];
167 b6[i] = b_des[i];
168
169 c_asc[i] = hdrl_random_uniform_double(state, 10., 20.);
170 c2[i] = c_asc[i];
171 c_des[i] = c_asc[i];
172 c7[i] = c_des[i];
173
174 d_asc[i] = hdrl_random_poisson(state, 300.);
175 d3[i] = d_asc[i];
176 d_des[i] = d_asc[i];
177 d8[i] = d_des[i];
178
179 e_asc[i] = (hdrl_value){hdrl_random_normal(state, 3.5, 1.5),
180 hdrl_random_normal(state, 2.5, 1.0) };
181 e4[i] = (hdrl_value){e_asc[i].data, e_asc[i].error};
182 e_des[i] = (hdrl_value){e_asc[i].data, e_asc[i].error};
183 e9[i] = (hdrl_value){e_des[i].data, e_des[i].error};
184 }
185 hdrl_random_state_delete(state);
186
187 /* Prepare arrays for ascending order */
188 void * arrs_asc[ 4] = { b_asc, c_asc, d_asc, e_asc};
189 hdrl_sort_type types_asc[4] = { HDRL_SORT_INT, HDRL_SORT_DOUBLE, HDRL_SORT_CPL_SIZE, HDRL_SORT_HDRL_VALUE};
190
191 /* Prepare arrays for descending order */
192 void * arrs_des[ 4] = { b_des, c_des, d_des, e_des};
193 hdrl_sort_type types_des[4] = { HDRL_SORT_INT, HDRL_SORT_DOUBLE, HDRL_SORT_CPL_SIZE, HDRL_SORT_HDRL_VALUE};
194
195
196 /* Test 1: Random array INT - ASCENDING */
197 sort_array_index( a1, N, b1, HDRL_SORT_INT, CPL_SORT_ASCENDING);
198 cpl_test_error(CPL_ERROR_NONE);
199
200 /* Test 2: Random array DOUBLE - ASCENDING */
201 sort_array_index( a2, N, c2, HDRL_SORT_DOUBLE, CPL_SORT_ASCENDING);
202 cpl_test_error(CPL_ERROR_NONE);
203
204 /* Test 3: Random array CPL_SIZE - ASCENDING */
205 sort_array_index( a3, N, d3, HDRL_SORT_CPL_SIZE, CPL_SORT_ASCENDING);
206 cpl_test_error(CPL_ERROR_NONE);
207
208 /* Test 4: Random array HDRL_VALUE - ASCENDING */
209 sort_array_index( a4, N, e4, HDRL_SORT_HDRL_VALUE, CPL_SORT_ASCENDING);
210 cpl_test_error(CPL_ERROR_NONE);
211
212 /* Test 5: Ramdom arrays --> order all with the same function - ASCENDING */
213 sort_arrays_index(a_asc, N, arrs_asc, 4, types_asc, CPL_SORT_DESCENDING);
214 cpl_test_error(CPL_ERROR_NONE);
215
216
217 /* Test 6: Random array INT - DESCENDING */
218 sort_array_index( a6, N, b6, HDRL_SORT_INT, CPL_SORT_DESCENDING);
219 cpl_test_error(CPL_ERROR_NONE);
220
221 /* Test 7: Random array DOUBLE - DESCENDING */
222 sort_array_index( a7, N, c7, HDRL_SORT_DOUBLE, CPL_SORT_DESCENDING);
223 cpl_test_error(CPL_ERROR_NONE);
224
225 /* Test 8: Random array CPL_SIZE - DESCENDING */
226 sort_array_index( a8, N, d8, HDRL_SORT_CPL_SIZE, CPL_SORT_DESCENDING);
227 cpl_test_error(CPL_ERROR_NONE);
228
229 /* Test 9: Random array HDRL_VALUE - DESCENDING */
230 sort_array_index( a9, N, e9, HDRL_SORT_HDRL_VALUE, CPL_SORT_DESCENDING);
231 cpl_test_error(CPL_ERROR_NONE);
232
233 /* Test 10: Ramdom arrays --> order all with the same function - DESCENDING */
234 sort_arrays_index(a_des, N, arrs_des, 4, types_des, CPL_SORT_ASCENDING);
235 cpl_test_error(CPL_ERROR_NONE);
236
237 cpl_free(a_asc);
238 cpl_free(a_des);
239 cpl_free(a1);
240 cpl_free(a2);
241 cpl_free(a3);
242 cpl_free(a4);
243 cpl_free(a6);
244 cpl_free(a7);
245 cpl_free(a8);
246 cpl_free(a9);
247
248 cpl_free(b_asc);
249 cpl_free(b_des);
250 cpl_free(b1);
251 cpl_free(b6);
252
253
254 cpl_free(c_asc);
255 cpl_free(c_des);
256 cpl_free(c2);
257 cpl_free(c7);
258
259 cpl_free(d_asc);
260 cpl_free(d_des);
261 cpl_free(d3);
262 cpl_free(d8);
263
264 cpl_free(e_asc);
265 cpl_free(e_des);
266 cpl_free(e4);
267 cpl_free(e9);
268}
269
270void test_sort_arrays_fixed(void)
271{
272 /*** Testing the results fixed by hand ***/
273
274 double x_asc[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4};
275 double x_des[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4};
276 double x1[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4};
277 double x2[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4};
278 double x3[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4};
279 double x4[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4};
280 double x6[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4};
281 double x7[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4};
282 double x8[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4};
283 double x9[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4};
284 double x_corr_asc[10] = {-3.5, -0.5, 0.33, 2.66, 4.4, 5.1, 5.2, 5.3, 5.4, 5.5};
285 double x_corr_des[10] = { 5.5, 5.4, 5.3, 5.2, 5.1, 4.4, 2.66, 0.33,-0.5,-3.5};
286
287 int i_asc[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
288 int i_des[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
289 int i_1[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
290 int i_6[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
291 int i_corr_asc[10] = { 3, 0, 1, 2, 9, 4, 5, 6, 7, 8};
292 int i_corr_des[10] = { 8, 7, 6, 5, 4, 9, 2, 1, 0, 3};
293
294 double db_asc[10] = { 0.,-1.,-2.,-3.,-4., 5., 6., 7., 8., 9.};
295 double db_des[10] = { 0.,-1.,-2.,-3.,-4., 5., 6., 7., 8., 9.};
296 double db_2[10] = { 0.,-1.,-2.,-3.,-4., 5., 6., 7., 8., 9.};
297 double db_7[10] = { 0.,-1.,-2.,-3.,-4., 5., 6., 7., 8., 9.};
298 double db_corr_asc[10] = {-3., 0.,-1.,-2., 9.,-4., 5., 6., 7., 8.};
299 double db_corr_des[10] = { 8., 7., 6., 5.,-4., 9.,-2.,-1., 0.,-3.};
300
301 cpl_size cp_asc[10] = { 0,-1,-2,-3,-4,-5,-6,-7,-8,-9};
302 cpl_size cp_des[10] = { 0,-1,-2,-3,-4,-5,-6,-7,-8,-9};
303 cpl_size cp_3[10] = { 0,-1,-2,-3,-4,-5,-6,-7,-8,-9};
304 cpl_size cp_8[10] = { 0,-1,-2,-3,-4,-5,-6,-7,-8,-9};
305 cpl_size cp_corr_asc[10] = {-3, 0,-1,-2,-9,-4,-5,-6,-7,-8};
306 cpl_size cp_corr_des[10] = {-8,-7,-6,-5,-4,-9,-2,-1, 0,-3};
307
308 hdrl_value hv_asc[10] = {(hdrl_value){-3.5, 0.1}, (hdrl_value){-0.5, 0.2}, (hdrl_value){ 0.001, 0.3}, (hdrl_value){ 1.1, 0.4}, (hdrl_value){1.2, 0.5},
309 (hdrl_value){ 5.0, 0.6}, (hdrl_value){ 6.0, 0.7}, (hdrl_value){ 7.0, 0.8}, (hdrl_value){ 8.0, 0.9}, (hdrl_value){9.0, 1.0} };
310 hdrl_value hv_des[10] = {(hdrl_value){-3.5, 0.1}, (hdrl_value){-0.5, 0.2}, (hdrl_value){ 0.001, 0.3}, (hdrl_value){ 1.1, 0.4}, (hdrl_value){1.2, 0.5},
311 (hdrl_value){ 5.0, 0.6}, (hdrl_value){ 6.0, 0.7}, (hdrl_value){ 7.0, 0.8}, (hdrl_value){ 8.0, 0.9}, (hdrl_value){9.0, 1.0} };
312 hdrl_value hv_4[10] = {(hdrl_value){-3.5, 0.1}, (hdrl_value){-0.5, 0.2}, (hdrl_value){ 0.001, 0.3}, (hdrl_value){ 1.1, 0.4}, (hdrl_value){1.2, 0.5},
313 (hdrl_value){ 5.0, 0.6}, (hdrl_value){ 6.0, 0.7}, (hdrl_value){ 7.0, 0.8}, (hdrl_value){ 8.0, 0.9}, (hdrl_value){9.0, 1.0} };
314 hdrl_value hv_9[10] = {(hdrl_value){-3.5, 0.1}, (hdrl_value){-0.5, 0.2}, (hdrl_value){ 0.001, 0.3}, (hdrl_value){ 1.1, 0.4}, (hdrl_value){1.2, 0.5},
315 (hdrl_value){ 5.0, 0.6}, (hdrl_value){ 6.0, 0.7}, (hdrl_value){ 7.0, 0.8}, (hdrl_value){ 8.0, 0.9}, (hdrl_value){9.0, 1.0} };
316 hdrl_value hv_corr_asc[10] = {(hdrl_value){ 1.1, 0.4}, (hdrl_value){-3.5, 0.1}, (hdrl_value){-0.5, 0.2}, (hdrl_value){ 0.001, 0.3}, (hdrl_value){9.0, 1.0},
317 (hdrl_value){ 1.2, 0.5}, (hdrl_value){ 5.0, 0.6}, (hdrl_value){ 6.0, 0.7}, (hdrl_value){ 7.0, 0.8}, (hdrl_value){8.0, 0.9} };
318 hdrl_value hv_corr_des[10] = {(hdrl_value){ 8.0, 0.9}, (hdrl_value){ 7.0, 0.8}, (hdrl_value){ 6.0, 0.7}, (hdrl_value){ 5.0, 0.6}, (hdrl_value){1.2, 0.5},
319 (hdrl_value){ 9.0, 1.0}, (hdrl_value){ 0.001, 0.3}, (hdrl_value){-0.5, 0.2}, (hdrl_value){-3.5, 0.1}, (hdrl_value){1.1, 0.4} };
320
321 /* Prepare arrays for ascending order */
322 void * arrs_asc[ 4] = { i_asc, db_asc, cp_asc, hv_asc};
323 hdrl_sort_type types_asc[4] = { HDRL_SORT_INT, HDRL_SORT_DOUBLE, HDRL_SORT_CPL_SIZE, HDRL_SORT_HDRL_VALUE};
324
325 /* Prepare arrays for descending order */
326 void * arrs_des[ 4] = { i_des, db_des, cp_des, hv_des};
327 hdrl_sort_type types_des[4] = { HDRL_SORT_INT, HDRL_SORT_DOUBLE, HDRL_SORT_CPL_SIZE, HDRL_SORT_HDRL_VALUE};
328
329
330 /* Test 1: Fixed array INT - ASCCENDING */
331 sort_array_index(x1, 10, i_1, HDRL_SORT_INT, CPL_SORT_ASCENDING);
332 cpl_test_error(CPL_ERROR_NONE);
333 for (cpl_size ind = 0; ind < 10; ind++) {
334 cpl_test_eq(x1[ ind], x_corr_asc[ind]);
335 cpl_test_eq(i_1[ind], i_corr_asc[ind]);
336 }
337
338 /* Test 2: Fixed array DOUBLE - ASCCENDING */
339 sort_array_index(x2, 10, db_2, HDRL_SORT_DOUBLE, CPL_SORT_ASCENDING);
340 cpl_test_error(CPL_ERROR_NONE);
341 for (cpl_size ind = 0; ind < 10; ind++) {
342 cpl_test_eq(x2[ ind], x_corr_asc[ ind]);
343 cpl_test_eq(db_2[ind], db_corr_asc[ind]);
344 }
345
346 /* Test 3: Fixed array CPL_SIZE - ASCCENDING */
347 sort_array_index(x3, 10, cp_3, HDRL_SORT_CPL_SIZE, CPL_SORT_ASCENDING);
348 cpl_test_error(CPL_ERROR_NONE);
349 for (cpl_size ind = 0; ind < 10; ind++) {
350 cpl_test_eq(x3[ ind], x_corr_asc[ ind]);
351 cpl_test_eq(cp_3[ind], cp_corr_asc[ind]);
352 }
353
354 /* Test 4: Fixed array HDRL_VALUE - ASCCENDING */
355 sort_array_index(x4, 10, hv_4, HDRL_SORT_HDRL_VALUE, CPL_SORT_ASCENDING);
356 cpl_test_error(CPL_ERROR_NONE);
357 for (cpl_size ind = 0; ind < 10; ind++) {
358 cpl_test_eq(x4[ ind], x_corr_asc[ ind]);
359 cpl_test_eq(hv_4[ind].data, hv_corr_asc[ind].data);
360 cpl_test_eq(hv_4[ind].error, hv_corr_asc[ind].error);
361 }
362
363 /* Test 5: Fixed arrays --> order all with the same function - ASCCENDING */
364 sort_arrays_index(x_asc, 10, arrs_asc, 4, types_asc, CPL_SORT_ASCENDING);
365 cpl_test_error(CPL_ERROR_NONE);
366 for (cpl_size ind = 0; ind < 10; ind++) {
367 cpl_test_eq(x_asc[ ind], x_corr_asc[ ind]);
368 cpl_test_eq(i_asc[ ind], i_corr_asc[ ind]);
369 cpl_test_eq(db_asc[ind], db_corr_asc[ind]);
370 cpl_test_eq(cp_asc[ind], cp_corr_asc[ind]);
371 cpl_test_eq(hv_asc[ind].data, hv_corr_asc[ind].data);
372 cpl_test_eq(hv_asc[ind].error, hv_corr_asc[ind].error);
373 }
374
375
376 /* Test 6: Fixed array INT - DESCENDING */
377 sort_array_index(x6, 10, i_6, HDRL_SORT_INT, CPL_SORT_DESCENDING);
378 cpl_test_error(CPL_ERROR_NONE);
379 for (cpl_size ind = 0; ind < 10; ind++) {
380 cpl_test_eq(x6[ ind], x_corr_des[ind]);
381 cpl_test_eq(i_6[ind], i_corr_des[ind]);
382 }
383
384 /* Test 7: Fixed array DOUBLE - DESCENDING */
385 sort_array_index(x7, 10, db_7, HDRL_SORT_DOUBLE, CPL_SORT_DESCENDING);
386 cpl_test_error(CPL_ERROR_NONE);
387 for (cpl_size ind = 0; ind < 10; ind++) {
388 cpl_test_eq(x7[ ind], x_corr_des[ ind]);
389 cpl_test_eq(db_7[ind], db_corr_des[ind]);
390 }
391
392 /* Test 8: Fixed array CPL_SIZE - DESCENDING */
393 sort_array_index(x8, 10, cp_8, HDRL_SORT_CPL_SIZE, CPL_SORT_DESCENDING);
394 cpl_test_error(CPL_ERROR_NONE);
395 for (cpl_size ind = 0; ind < 10; ind++) {
396 cpl_test_eq(x8[ ind], x_corr_des[ ind]);
397 cpl_test_eq(cp_8[ind], cp_corr_des[ind]);
398 }
399
400 /* Test 9: Fixed array HDRL_VALUE - DESCENDING */
401 sort_array_index(x9, 10, hv_9, HDRL_SORT_HDRL_VALUE, CPL_SORT_DESCENDING);
402 cpl_test_error(CPL_ERROR_NONE);
403 for (cpl_size ind = 0; ind < 10; ind++) {
404 cpl_test_eq(x9[ ind], x_corr_des[ ind]);
405 cpl_test_eq(hv_9[ind].data, hv_corr_des[ind].data);
406 cpl_test_eq(hv_9[ind].error, hv_corr_des[ind].error);
407 }
408
409 /* Test 10: Fixed arrays --> order all with the same function - DESCENDING */
410 sort_arrays_index(x_des, 10, arrs_des, 4, types_des, CPL_SORT_DESCENDING);
411 cpl_test_error(CPL_ERROR_NONE);
412 for (cpl_size ind = 0; ind < 10; ind++) {
413 cpl_test_eq(x_des[ ind], x_corr_des[ ind]);
414 cpl_test_eq(i_des[ ind], i_corr_des[ ind]);
415 cpl_test_eq(db_des[ind], db_corr_des[ind]);
416 cpl_test_eq(cp_des[ind], cp_corr_des[ind]);
417 cpl_test_eq(hv_des[ind].data, hv_corr_des[ind].data);
418 cpl_test_eq(hv_des[ind].error, hv_corr_des[ind].error);
419 }
420}
421
422int main(void)
423{
424 cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING);
425
426 /* Test 3 diferent functions: qsort in C, hdrl_function and cpl_function
427 * in ascending and descending order */
428 test_cmp_sort_func(CPL_SORT_ASCENDING);
429 test_cmp_sort_func(CPL_SORT_DESCENDING);
430
431 /* Test sort arrays by index, the first is ordering and the nexts by index */
432 test_sort_arrays_random();
433
434 /* Test sort arrays by index, equal to previously but checking the results */
435 test_sort_arrays_fixed();
436
437 return cpl_test_end(0);
438}
cpl_error_code sort_array(void *a, cpl_size nE, cpl_size sE, hdrl_sort_type type, cpl_sort_direction dir)
sort_array hdrl function for order arrays with know types. Using the type parameter for select the co...
cpl_error_code sort_arrays_index(double *a, cpl_size nE, void **bs, cpl_size nA, hdrl_sort_type *types, cpl_sort_direction dir)
sort_arrays_index hdrl function for sort several arrays The alghorithm sort 'a' and in the same way s...
cpl_error_code sort_array_index(double *a, cpl_size nE, void *b, hdrl_sort_type type, cpl_sort_direction dir)
sort_array_index hdrl function for sort two arrays The alghorithm sort 'a' and in the same way sort t...