ICU-3138 test internal sort function
X-SVN-Rev: 12752
This commit is contained in:
parent
9c0b972277
commit
8e7d1112f4
@ -46,7 +46,7 @@ cnmdptst.o cnormtst.o cnumtst.o cregrtst.o crestst.o creststn.o cturtst.o \
|
||||
cucdapi.o cucdtst.o custrtst.o cstrcase.o cutiltst.o encoll.o nucnvtst.o nccbtst.o bocu1tst.o \
|
||||
cbiditst.o cbididat.o eurocreg.o udatatst.o utf16tst.o utransts.o \
|
||||
ncnvfbts.o ncnvtst.o putiltst.o cstrtest.o mstrmtst.o utf8tst.o ucmptst.o \
|
||||
stdnmtst.o ctstdep.o usrchtst.o custrtrn.o trietest.o usettest.o uenumtst.o \
|
||||
stdnmtst.o ctstdep.o usrchtst.o custrtrn.o sorttest.o trietest.o usettest.o uenumtst.o \
|
||||
idnatest.o nfsprep.o spreptst.o sprpdata.o
|
||||
|
||||
DEPS = $(OBJECTS:.o=.d)
|
||||
|
@ -325,6 +325,10 @@ SOURCE=.\chashtst.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sorttest.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\trietest.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -268,6 +268,9 @@
|
||||
<File
|
||||
RelativePath=".\chashtst.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\sorttest.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\trietest.c">
|
||||
</File>
|
||||
|
@ -25,6 +25,7 @@ void addMemoryStreamTest(TestNode** root);
|
||||
void addTrieTest(TestNode** root);
|
||||
void addEnumerationTest(TestNode** root);
|
||||
void addPosixTest(TestNode** root);
|
||||
void addSortTest(TestNode** root);
|
||||
|
||||
void addUtility(TestNode** root);
|
||||
|
||||
@ -41,4 +42,5 @@ void addUtility(TestNode** root)
|
||||
addMemoryStreamTest(root);
|
||||
addEnumerationTest(root);
|
||||
addPosixTest(root);
|
||||
addSortTest(root);
|
||||
}
|
||||
|
92
icu4c/source/test/cintltst/sorttest.c
Normal file
92
icu4c/source/test/cintltst/sorttest.c
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2003, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
* file name: csorttst.c
|
||||
* encoding: US-ASCII
|
||||
* tab size: 8 (not used)
|
||||
* indentation:4
|
||||
*
|
||||
* created on: 2003aug04
|
||||
* created by: Markus W. Scherer
|
||||
*
|
||||
* Test internal sorting functions.
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "cmemory.h"
|
||||
#include "cintltst.h"
|
||||
#include "uarrsort.h"
|
||||
|
||||
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
|
||||
|
||||
/* compare only the top 28 bits of int32_t items (bits 3..0 contain the original index) */
|
||||
static int32_t U_CALLCONV
|
||||
_int32Top28Comparator(const void *context, const void *left, const void *right) {
|
||||
return (*(const int32_t *)left>>4) - (*(const int32_t *)right>>4);
|
||||
}
|
||||
|
||||
void
|
||||
SortTest(void) {
|
||||
uint16_t small[]={ 10, 8, 1, 2, 5, 4, 3, 9, 7, 6 };
|
||||
int32_t medium[]={ 10, 8, 1, 2, 5, 5, 6, 4, 3, 9, 7, 5 };
|
||||
uint32_t large[]={ 21, 10, 20, 19, 11, 12, 13, 10, 10, 10, 10,
|
||||
8, 1, 2, 5, 10, 10, 4, 17, 18, 3, 9, 10, 7, 6, 14, 15, 16 };
|
||||
|
||||
int32_t i;
|
||||
UErrorCode errorCode;
|
||||
|
||||
/* sort small array (stable) */
|
||||
errorCode=U_ZERO_ERROR;
|
||||
uprv_sortArray(small, LENGTHOF(small), sizeof(small[0]), uprv_uint16Comparator, NULL, TRUE, &errorCode);
|
||||
if(U_FAILURE(errorCode)) {
|
||||
log_err("uprv_sortArray(small) failed - %s\n", u_errorName(errorCode));
|
||||
return;
|
||||
}
|
||||
for(i=1; i<LENGTHOF(small); ++i) {
|
||||
if(small[i-1]>small[i]) {
|
||||
log_err("uprv_sortArray(small) mis-sorted [%d]=%u > [%d]=%u\n", i-1, small[i-1], i, small[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* for medium, add bits that will not be compared, to test stability */
|
||||
for(i=0; i<LENGTHOF(medium); ++i) {
|
||||
medium[i]=(medium[i]<<4)|i;
|
||||
}
|
||||
|
||||
/* sort medium array (stable) */
|
||||
uprv_sortArray(medium, LENGTHOF(medium), sizeof(medium[0]), _int32Top28Comparator, NULL, TRUE, &errorCode);
|
||||
if(U_FAILURE(errorCode)) {
|
||||
log_err("uprv_sortArray(medium) failed - %s\n", u_errorName(errorCode));
|
||||
return;
|
||||
}
|
||||
for(i=1; i<LENGTHOF(medium); ++i) {
|
||||
if(medium[i-1]>=medium[i]) {
|
||||
log_err("uprv_sortArray(medium) mis-sorted [%d]=%u > [%d]=%u\n", i-1, medium[i-1], i, medium[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* sort large array (not stable) */
|
||||
errorCode=U_ZERO_ERROR;
|
||||
uprv_sortArray(large, LENGTHOF(large), sizeof(large[0]), uprv_uint32Comparator, NULL, FALSE, &errorCode);
|
||||
if(U_FAILURE(errorCode)) {
|
||||
log_err("uprv_sortArray(large) failed - %s\n", u_errorName(errorCode));
|
||||
return;
|
||||
}
|
||||
for(i=1; i<LENGTHOF(large); ++i) {
|
||||
if(large[i-1]>large[i]) {
|
||||
log_err("uprv_sortArray(large) mis-sorted [%d]=%u > [%d]=%u\n", i-1, large[i-1], i, large[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
addSortTest(TestNode** root) {
|
||||
addTest(root, &SortTest, "tsutil/SortTest");
|
||||
}
|
Loading…
Reference in New Issue
Block a user