]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/sorttest.c
2 *******************************************************************************
4 * Copyright (C) 2003, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: csorttst.c
10 * tab size: 8 (not used)
13 * created on: 2003aug04
14 * created by: Markus W. Scherer
16 * Test internal sorting functions.
19 #include "unicode/utypes.h"
24 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
28 uint16_t small
[]={ 8, 1, 2, 5, 4, 3, 7, 6 };
29 int32_t medium
[]={ 10, 8, 1, 2, 5, 5, -1, 6, 4, 3, 9, 7, 5 };
30 uint32_t large
[]={ 21, 10, 20, 19, 11, 12, 13, 10, 10, 10, 10,
31 8, 1, 2, 5, 10, 10, 4, 17, 18, 3, 9, 10, 7, 6, 14, 15, 16 };
36 /* sort small array (stable) */
37 errorCode
=U_ZERO_ERROR
;
38 uprv_sortArray(small
, LENGTHOF(small
), sizeof(small
[0]), uprv_uint16Comparator
, NULL
, TRUE
, &errorCode
);
39 if(U_FAILURE(errorCode
)) {
40 log_err("uprv_sortArray(small) failed - %s\n", u_errorName(errorCode
));
43 for(i
=1; i
<LENGTHOF(small
); ++i
) {
44 if(small
[i
-1]>small
[i
]) {
45 log_err("uprv_sortArray(small) mis-sorted [%d]=%u > [%d]=%u\n", i
-1, small
[i
-1], i
, small
[i
]);
50 /* for medium, add bits that will not be compared, to test stability */
51 for(i
=0; i
<LENGTHOF(medium
); ++i
) {
52 medium
[i
]=(medium
[i
]<<4)|i
;
55 /* sort medium array (stable) */
56 uprv_sortArray(medium
, LENGTHOF(medium
), sizeof(medium
[0]), uprv_int32Comparator
, NULL
, TRUE
, &errorCode
);
57 if(U_FAILURE(errorCode
)) {
58 log_err("uprv_sortArray(medium) failed - %s\n", u_errorName(errorCode
));
61 for(i
=1; i
<LENGTHOF(medium
); ++i
) {
62 if(medium
[i
-1]>=medium
[i
]) {
63 log_err("uprv_sortArray(medium) mis-sorted [%d]=%u > [%d]=%u\n", i
-1, medium
[i
-1], i
, medium
[i
]);
68 /* sort large array (not stable) */
69 errorCode
=U_ZERO_ERROR
;
70 uprv_sortArray(large
, LENGTHOF(large
), sizeof(large
[0]), uprv_uint32Comparator
, NULL
, FALSE
, &errorCode
);
71 if(U_FAILURE(errorCode
)) {
72 log_err("uprv_sortArray(large) failed - %s\n", u_errorName(errorCode
));
75 for(i
=1; i
<LENGTHOF(large
); ++i
) {
76 if(large
[i
-1]>large
[i
]) {
77 log_err("uprv_sortArray(large) mis-sorted [%d]=%u > [%d]=%u\n", i
-1, large
[i
-1], i
, large
[i
]);
84 addSortTest(TestNode
** root
);
87 addSortTest(TestNode
** root
) {
88 addTest(root
, &SortTest
, "tsutil/sorttest/SortTest");