00001
00010 #include <GKlib.h>
00011
00012 #define N 10000
00013
00014
00016
00017 void test_isort()
00018 {
00019 gk_idx_t i;
00020 int array[N];
00021
00022
00023 printf("Testing iisort...\n");
00024 for (i=0; i<N; i++)
00025 array[i] = RandomInRange(123432);
00026
00027 gk_isorti(N, array);
00028
00029 for (i=0; i<N-1; i++) {
00030 if (array[i] > array[i+1])
00031 printf("gk_isorti error at index %jd [%d %d]\n", (intmax_t)i, array[i], array[i+1]);
00032 }
00033
00034
00035
00036 printf("Testing disort...\n");
00037 for (i=0; i<N; i++)
00038 array[i] = RandomInRange(123432);
00039
00040 gk_isortd(N, array);
00041
00042 for (i=0; i<N-1; i++) {
00043 if (array[i] < array[i+1])
00044 printf("gk_isortd error at index %jd [%d %d]\n", (intmax_t)i, array[i], array[i+1]);
00045 }
00046
00047 }
00048
00049
00050
00052
00053 void test_fsort()
00054 {
00055 gk_idx_t i;
00056 float array[N];
00057
00058
00059 printf("Testing ifsort...\n");
00060 for (i=0; i<N; i++)
00061 array[i] = RandomInRange(123432)/(1.0+RandomInRange(645323));
00062
00063 gk_fsorti(N, array);
00064
00065 for (i=0; i<N-1; i++) {
00066 if (array[i] > array[i+1])
00067 printf("gk_fsorti error at index %jd [%f %f]\n", (intmax_t)i, array[i], array[i+1]);
00068 }
00069
00070
00071
00072 printf("Testing dfsort...\n");
00073 for (i=0; i<N; i++)
00074 array[i] = RandomInRange(123432)/(1.0+RandomInRange(645323));
00075
00076 gk_fsortd(N, array);
00077
00078 for (i=0; i<N-1; i++) {
00079 if (array[i] < array[i+1])
00080 printf("gk_fsortd error at index %jd [%f %f]\n", (intmax_t)i, array[i], array[i+1]);
00081 }
00082
00083 }
00084
00085
00086
00088
00089 void test_idxsort()
00090 {
00091 gk_idx_t i;
00092 gk_idx_t array[N];
00093
00094
00095 printf("Testing idxsorti...\n");
00096 for (i=0; i<N; i++)
00097 array[i] = RandomInRange(123432);
00098
00099 gk_idxsorti(N, array);
00100
00101 for (i=0; i<N-1; i++) {
00102 if (array[i] > array[i+1])
00103 printf("gk_idxsorti error at index %zd [%zd %zd]\n", (ssize_t)i, (ssize_t)array[i], (ssize_t)array[i+1]);
00104 }
00105
00106
00107
00108 printf("Testing idxsortd...\n");
00109 for (i=0; i<N; i++)
00110 array[i] = RandomInRange(123432);
00111
00112 gk_idxsortd(N, array);
00113
00114 for (i=0; i<N-1; i++) {
00115 if (array[i] < array[i+1])
00116 printf("gk_idxsortd error at index %zd [%zd %zd]\n", (ssize_t)i, (ssize_t)array[i], (ssize_t)array[i+1]);
00117 }
00118
00119 }
00120
00121
00122
00123
00125
00126 void test_ikvsort()
00127 {
00128 gk_idx_t i;
00129 gk_ikv_t array[N];
00130
00131
00132 printf("Testing ikvsorti...\n");
00133 for (i=0; i<N; i++) {
00134 array[i].key = RandomInRange(123432);
00135 array[i].val = i;
00136 }
00137
00138 gk_ikvsorti(N, array);
00139
00140 for (i=0; i<N-1; i++) {
00141 if (array[i].key > array[i+1].key)
00142 printf("gk_ikvsorti error at index %jd [%d %d] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
00143 }
00144
00145
00146
00147 printf("Testing ikvsortd...\n");
00148 for (i=0; i<N; i++) {
00149 array[i].key = RandomInRange(123432);
00150 array[i].val = i;
00151 }
00152
00153 gk_ikvsortd(N, array);
00154
00155 for (i=0; i<N-1; i++) {
00156 if (array[i].key < array[i+1].key)
00157 printf("gk_ikvsortd error at index %jd [%d %d] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
00158 }
00159
00160 }
00161
00162
00163
00164
00166
00167 void test_fkvsort()
00168 {
00169 gk_idx_t i;
00170 gk_fkv_t array[N];
00171
00172
00173 printf("Testing fkvsorti...\n");
00174 for (i=0; i<N; i++) {
00175 array[i].key = RandomInRange(123432)/(1.0+RandomInRange(645323));
00176 array[i].val = i;
00177 }
00178
00179 gk_fkvsorti(N, array);
00180
00181 for (i=0; i<N-1; i++) {
00182 if (array[i].key > array[i+1].key)
00183 printf("gk_fkvsorti error at index %jd [%f %f] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
00184 }
00185
00186
00187
00188 printf("Testing fkvsortd...\n");
00189 for (i=0; i<N; i++) {
00190 array[i].key = RandomInRange(123432)/(1.0+RandomInRange(645323));
00191 array[i].val = i;
00192 }
00193
00194 gk_fkvsortd(N, array);
00195
00196 for (i=0; i<N-1; i++) {
00197 if (array[i].key < array[i+1].key)
00198 printf("gk_fkvsortd error at index %jd [%f %f] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
00199 }
00200
00201 }
00202
00203
00204
00206
00207 void test_dkvsort()
00208 {
00209 gk_idx_t i;
00210 gk_dkv_t array[N];
00211
00212
00213 printf("Testing dkvsorti...\n");
00214 for (i=0; i<N; i++) {
00215 array[i].key = RandomInRange(123432)/(1.0+RandomInRange(645323));
00216 array[i].val = i;
00217 }
00218
00219 gk_dkvsorti(N, array);
00220
00221 for (i=0; i<N-1; i++) {
00222 if (array[i].key > array[i+1].key)
00223 printf("gk_dkvsorti error at index %jd [%lf %lf] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
00224 }
00225
00226
00227
00228 printf("Testing dkvsortd...\n");
00229 for (i=0; i<N; i++) {
00230 array[i].key = RandomInRange(123432)/(1.0+RandomInRange(645323));
00231 array[i].val = i;
00232 }
00233
00234 gk_dkvsortd(N, array);
00235
00236 for (i=0; i<N-1; i++) {
00237 if (array[i].key < array[i+1].key)
00238 printf("gk_dkvsortd error at index %jd [%lf %lf] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
00239 }
00240
00241 }
00242
00243
00244
00246
00247 void test_skvsort()
00248 {
00249 gk_idx_t i;
00250 gk_skv_t array[N];
00251 char line[256];
00252
00253
00254 printf("Testing skvsorti...\n");
00255 for (i=0; i<N; i++) {
00256 sprintf(line, "%d", RandomInRange(123432));
00257 array[i].key = gk_strdup(line);
00258 array[i].val = i;
00259 }
00260
00261 gk_skvsorti(N, array);
00262
00263 for (i=0; i<N-1; i++) {
00264 if (strcmp(array[i].key, array[i+1].key) > 0)
00265 printf("gk_skvsorti error at index %jd [%s %s] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
00266 }
00267
00268
00269
00270 printf("Testing skvsortd...\n");
00271 for (i=0; i<N; i++) {
00272 sprintf(line, "%d", RandomInRange(123432));
00273 array[i].key = gk_strdup(line);
00274 array[i].val = i;
00275 }
00276
00277 gk_skvsortd(N, array);
00278
00279 for (i=0; i<N-1; i++) {
00280
00281 if (strcmp(array[i].key, array[i+1].key) < 0)
00282 printf("gk_skvsortd error at index %jd [%s %s] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
00283 }
00284
00285 }
00286
00287
00288
00290
00291 void test_idxkvsort()
00292 {
00293 gk_idx_t i;
00294 gk_idxkv_t array[N];
00295
00296
00297 printf("Testing idxkvsorti...\n");
00298 for (i=0; i<N; i++) {
00299 array[i].key = RandomInRange(123432);
00300 array[i].val = i;
00301 }
00302
00303 gk_idxkvsorti(N, array);
00304
00305 for (i=0; i<N-1; i++) {
00306 if (array[i].key > array[i+1].key)
00307 printf("gk_idxkvsorti error at index %zd [%zd %zd] [%zd %zd]\n",
00308 (ssize_t)i, (ssize_t)array[i].key, (ssize_t)array[i+1].key,
00309 (ssize_t)array[i].val, (ssize_t)array[i+1].val);
00310 }
00311
00312
00313
00314 printf("Testing idxkvsortd...\n");
00315 for (i=0; i<N; i++) {
00316 array[i].key = RandomInRange(123432);
00317 array[i].val = i;
00318 }
00319
00320 gk_idxkvsortd(N, array);
00321
00322 for (i=0; i<N-1; i++) {
00323 if (array[i].key < array[i+1].key)
00324 printf("gk_idxkvsortd error at index %zd [%zd %zd] [%zd %zd]\n",
00325 (ssize_t)i, (ssize_t)array[i].key, (ssize_t)array[i+1].key,
00326 (ssize_t)array[i].val, (ssize_t)array[i+1].val);
00327 }
00328
00329 }
00330
00331
00332
00333
00334 int main()
00335 {
00336 test_isort();
00337 test_fsort();
00338 test_idxsort();
00339
00340 test_ikvsort();
00341 test_fkvsort();
00342 test_dkvsort();
00343 test_skvsort();
00344 test_idxkvsort();
00345 }
00346