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