84 #define MAXerrorCount 100  
   86 #define FOREACHint_( ints ) FOREACHsetelement_( i2T, ints, i2) 
   87 #define FOREACHint4_( ints ) FOREACHsetelement_( i2T, ints, i4) 
   88 #define FOREACHint_i_( ints ) FOREACHsetelement_i_( i2T, ints, i2) 
   89 #define FOREACHintreverse_( ints ) FOREACHsetelementreverse_( i2T, ints, i2) 
   90 #define FOREACHintreverse12_( ints ) FOREACHsetelementreverse12_( i2T, ints, i2) 
   96 char prompt[]= 
"testqset N [M] [T5] -- Test qset.c and mem.c\n\ 
   98   If this test fails then qhull will not work.\n\ 
  100   Test qsets of 0..N integers with a check every M iterations (default ~log10)\n\ 
  101   Additional checking and logging if M is 1\n\ 
  103   T5 turns on memory logging (qset does not log)\n\ 
  112 #define fmax_( a,b )  ( ( a ) < ( b ) ? ( b ) : ( a ) ) 
  117 #define qh_MEMalign ((int)(fmax_(sizeof(realT), sizeof(void *)))) 
  118 #define qh_MEMbufsize 0x10000        
  119 #define qh_MEMinitbuf 0x20000       
  144     static int needs_cr= 0;  
 
  146     size_t fmtlen= strlen(
fmt);
 
  151         fprintf(stderr, 
"QH6232 qh_fprintf: fp not defined for '%s'", 
fmt);
 
  155         if(
fmt[fmtlen-1]==
'\n'){
 
  156             if(needs_cr && fmtlen>1){
 
  164     if(msgcode>=6000 && msgcode<7000){
 
  165         fprintf(fp, 
"Error TQ%d ", msgcode);
 
  173 int main(
int argc, 
char **argv);
 
  174 void readOptions(
int argc, 
char **argv, 
const char *promptstr, 
int *numInts, 
int *checkEvery, 
int *traceLevel);
 
  175 void setupMemory(
int tracelevel, 
int numInts, 
int **intarray);
 
  182 void testSettemp(
int numInts, 
int *intarray, 
int checkEvery);
 
  186 int log_i(
setT *set, 
const char *s, 
int i, 
int numInts, 
int checkEvery);
 
  187 void checkSetContents(
const char *name, 
setT *set, 
int count, 
int rangeA, 
int rangeB, 
int rangeC);
 
  189 int main(
int argc, 
char **argv) {
 
  193     int curlong, totlong;
 
  196 #if defined(_MSC_VER) && defined(_DEBUG) && defined(QHULL_CRTDBG)   
  197     _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) );
 
  198     _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG );
 
  199     _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR );
 
  213     printf(
"\n\nNot testing qh_setduplicate and qh_setfree2.\n  These routines use heap-allocated set contents.  See qhull tests.\n");
 
  217     if (curlong || totlong){
 
  218         qh_fprintf(stderr, 8043, 
"qh_memfreeshort: did not free %d bytes of long memory(%d pieces)\n", totlong, curlong);
 
  225         printf(
"testqset: OK\n\n");
 
  230 void readOptions(
int argc, 
char **argv, 
const char *promptstr, 
int *numInts, 
int *checkEvery, 
int *traceLevel)
 
  237     if (argc < 2 || argc > 4) {
 
  238         printf(
"%s", promptstr);
 
  241     numIntsArg= strtol(argv[1], &endp, 10);
 
  243         qh_fprintf(stderr, 6301, 
"First argument should be 1 or greater.  Got '%s'\n", argv[1]);
 
  247         qh_fprintf(stderr, 6302, 
"qset does not currently support 64-bit ints.  Maximum count is %d\n", 
MAXint);
 
  250     *numInts= (int)numIntsArg;
 
  252     if(argc==3 && argv[2][0]==
'T' && argv[2][1]==
'5' ){
 
  256     if(argc==4 || (argc==3 && !isTracing)){
 
  257         checkEveryArg= strtol(argv[2], &endp, 10);
 
  259             qh_fprintf(stderr, 6321, 
"checkEvery argument should be 1 or greater.  Got '%s'\n", argv[2]);
 
  263             qh_fprintf(stderr, 6322, 
"qset does not currently support 64-bit ints.  Maximum checkEvery is %d\n", 
MAXint);
 
  267             if(argv[3][0]==
'T' && argv[3][1]==
'5' ){
 
  271                 qh_fprintf(stderr, 6242, 
"Optional third argument must be 'T5'.  Got '%s'\n", argv[3]);
 
  275         *checkEvery= (int)checkEveryArg;
 
  282     if(numInts<0 || numInts*(
int)
sizeof(
int)<0){
 
  283         qh_fprintf(stderr, 6303, 
"qset does not currently support 64-bit ints.  Integer overflow\n");
 
  286     *intarray= 
qh_malloc(numInts * 
sizeof(
int));
 
  288         qh_fprintf(stderr, 6304, 
"Failed to allocate %d bytes of memory\n", numInts * 
sizeof(
int));
 
  291     for(i= 0; i<numInts; i++){
 
  311     qh_fprintf(stderr, 8002, 
"\n\nTesting qh_setappend 0..%d.  Test", numInts-1);
 
  312     for(i= 0; i<numInts; i++){
 
  313         isCheck= 
log_i(
ints, 
"i", i, numInts, checkEvery);
 
  320     qh_fprintf(stderr, 8014, 
"\n\nTesting qh_settruncate %d and 0.  Test", numInts/2);
 
  322         isCheck= 
log_i(
ints, 
"n", numInts/2, numInts, checkEvery);
 
  326     isCheck= 
log_i(
ints, 
"n", 0, numInts, checkEvery);
 
  330     qh_fprintf(stderr, 8003, 
"\n\nTesting qh_setappend2ndlast 0,0..%d.  Test 0", numInts-1);
 
  334     for(i= 0; i<numInts; i++){
 
  335         isCheck= 
log_i(
ints, 
"i", i, numInts, checkEvery);
 
  341     qh_fprintf(stderr, 8015, 
"\n\nTesting SETtruncate_ %d and 0.  Test", numInts/2);
 
  343         isCheck= 
log_i(
ints, 
"n", numInts/2, numInts, checkEvery);
 
  347     isCheck= 
log_i(
ints, 
"n", 0, numInts, checkEvery);
 
  359     qh_fprintf(stderr, 8003, 
"\n\nTesting qh_setdelnthsorted and qh_setaddnth 1..%d. Test", numInts-1);
 
  360     for(j=1; j<numInts; j++){  
 
  366             for(i= 0; i<j && i<100; i++){  
 
  367                 isCheck= 
log_i(
ints, 
"", i, numInts, checkEvery);
 
  387     qh_fprintf(stderr, 8016, 
"\n\nTesting qh_setappend_set 0..%d. Test", numInts-1);
 
  388     for(j=0; j<numInts; j++){
 
  389         if(
log_i(
ints, 
"j", j, numInts, numInts)){
 
  397             for(i= 0; i<=j && i<=20; i++){  
 
  398                 if(
log_i(
ints, 
"", i, numInts, numInts)){
 
  425     qh_fprintf(stderr, 8017, 
"\n\nTesting qh_setcompact and qh_setcopy 0..%d. Test", numInts-1);
 
  426     for(j=0; j<numInts; j++){
 
  427         if(
log_i(
ints, 
"j", j, numInts, checkEvery)){
 
  429                 for(k= 0; k<i%7; k++){
 
  454     qh_fprintf(stderr, 8018, 
"\n\nTesting qh_setdel*, qh_setaddsorted, and  0..%d. Test", numInts-1);
 
  455     for(j=0; j<numInts; j++){
 
  456         if(
log_i(
ints, 
"j", j, numInts, checkEvery)){
 
  510     qh_fprintf(stderr, 8019, 
"\n\nTesting qh_setequal*, qh_setin*, qh_setdel, qh_setdelnth, and qh_setlarger 0..%d. Test", numInts-1);
 
  511     for(j=0; j<numInts; j++){
 
  512         if(
log_i(
ints, 
"j", j, numInts, checkEvery)){
 
  521                 qh_fprintf(stderr, 6300, 
"testSetequalInEtc: set not equal to itself at length %d\n", j);
 
  525                 qh_fprintf(stderr, 6323, 
"testSetequalInEtc: empty set not equal to null set\n");
 
  530                     qh_fprintf(stderr, 6324, 
"testSetequalInEtc: non-empty set equal to empty set\n", j);
 
  545                     qh_fprintf(stderr, 6325, 
"testSetequalInEtc: modified set equal to original set at %d/2\n", j);
 
  549                     qh_fprintf(stderr, 6326, 
"qh_setequal_except: modified set not equal to original set except modified\n", j);
 
  553                     qh_fprintf(stderr, 6327, 
"qh_setequal_except: modified set equal to original set with wrong excepts\n", j);
 
  557                     qh_fprintf(stderr, 6328, 
"qh_setequal_skip: modified set not equal to original set except modified\n", j);
 
  561                     qh_fprintf(stderr, 6329, 
"qh_setequal_skip: modified set equal to original set with wrong excepts\n", j);
 
  564                 if(intarray+j/2+1!=
qh_setdel(ints3, intarray+j/2+1)){
 
  565                     qh_fprintf(stderr, 6330, 
"qh_setdel: failed to find added element\n", j);
 
  574                     qh_fprintf(stderr, 6331, 
"qh_setin: found deleted element\n");
 
  577                 if(j>4 && !
qh_setin(ints3, intarray+1)){
 
  578                     qh_fprintf(stderr, 6332, 
"qh_setin: did not find second element\n");
 
  581                 if(j>4 && !
qh_setin(ints3, intarray+j-2)){
 
  582                     qh_fprintf(stderr, 6333, 
"qh_setin: did not find last element\n");
 
  586                     qh_fprintf(stderr, 6334, 
"qh_setindex: found element in empty set\n");
 
  590                     qh_fprintf(stderr, 6335, 
"qh_setindex: found deleted element in set\n");
 
  594                     qh_fprintf(stderr, 6336, 
"qh_setindex: did not find first in set\n");
 
  598                     qh_fprintf(stderr, 6337, 
"qh_setindex: did not find last in set\n");
 
  619     qh_fprintf(stderr, 8020, 
"\n\nTesting qh_setlast, qh_setnew_delnthsorted, qh_setunique, and qh_setzero 0..%d. Test", numInts-1);
 
  620     for(j=0; j<numInts; j++){
 
  621         if(
log_i(
ints, 
"j", j, numInts, checkEvery)){
 
  624                     qh_fprintf(stderr, 6340, 
"qh_setunique: not able to append next element %d\n", i);
 
  631                     qh_fprintf(stderr, 6341, 
"qh_setunique: appended next element twice %d\n", i);
 
  635                     qh_fprintf(stderr, 6346, 
"qh_setunique: appended middle element twice %d/2\n", i);
 
  641                 qh_fprintf(stderr, 6339, 
"qh_setlast: returned last element of empty set\n");
 
  646                     qh_fprintf(stderr, 6338, 
"qh_setlast: wrong last element\n");
 
  649                 prepend= (j<100 ? j/4 : 0);
 
  652                     qh_fprintf(stderr, 6345, 
"qh_setnew_delnthsorted: Expecting %d elements, got %d\n", j+prepend-1, 
qh_setsize(ints2));
 
  656                 for(i= 0; i<prepend; i++){
 
  660                 for(i= 0; i<prepend; i++){
 
  690     qh_fprintf(stderr, 8021, 
"\n\nTesting qh_settemp* 0..%d. Test", numInts-1);
 
  691     for(j=0; j<numInts; j++){
 
  692         if(
log_i(
ints, 
"j", j, numInts, checkEvery)){
 
  707                     qh_fprintf(stderr, 6343, 
"qh_settemppop: didn't pop the push\n");
 
  725 int log_i(
setT *set, 
const char *s, 
int i, 
int numInts, 
int checkEvery)
 
  732     if(*s || checkEvery==1){
 
  736             if(i==11 && checkEvery==1){
 
  737                 qh_fprintf(stderr, 8005, 
"\nResults after 10: ");
 
  758     if(i<1000 || i%checkEvery==0 || i== scale || i==numInts-1){
 
  789         qh_fprintf(stderr, 6305, 
"%s: SETreturnsize_() returned %d while qh_setsize() returns %d\n", 
name, actualSize, 
qh_setsize(set));
 
  791     }
else if(actualSize!=count){
 
  792         qh_fprintf(stderr, 6306, 
"%s: Expecting %d elements for set.  Got %d elements\n", 
name, count, actualSize);
 
  797             qh_fprintf(stderr, 6307, 
"%s: Got empty set instead of count %d, rangeA %d, rangeB %d, rangeC %d\n", 
name, count, rangeA, rangeB, rangeC);
 
  828             qh_fprintf(stderr, 6311, 
"%s: Expecting SETIndex_(set, pointer-to-%d) to be %d.  Got %d\n", 
name, *i2, i, 
SETindex_(set, i2));
 
  832             qh_fprintf(stderr, 6312, 
"%s: SETref_(i2) [%p] does not point to i2 (the %d'th element)\n", 
name, 
SETref_(i2), i);
 
  841             qh_fprintf(stderr, 6320, 
"%s: SETelemaddr_(set, %d, i2T) [%p] does not point to i2\n", 
name, i2_i, 
SETelemaddr_(set, i2_i, 
int));
 
  846                 qh_fprintf(stderr, 6314, 
"%s: First element is %d instead of SETfirst %d\n", 
name, *i2, first);
 
  850                 qh_fprintf(stderr, 6315, 
"%s: starts with %d instead of rangeA %d\n", 
name, *i2, rangeA);
 
  855             if(i2_i==1 && second!=*i2){
 
  856                 qh_fprintf(stderr, 6316, 
"%s: Second element is %d instead of SETsecond %d\n", 
name, *i2, second);
 
  866                 }
else if(rangeB==-1 && *i2==rangeC){
 
  872                     qh_fprintf(stderr, 6317, 
"%s: Expecting %d'th element to be %d.  Got %d\n", 
name, i2_i, prev, *i2);
 
  878             qh_fprintf(stderr, 6318, 
"%s: SETelem_(set, %d) [%p] is not i2 [%p] (the %d'th element)\n", 
name, i2_i, 
SETelem_(set, i2_i), i2, i2_i);
 
  882             qh_fprintf(stderr, 6319, 
"%s: SETelemt_(set, %d, i2T) [%p] is not SETelem_(set, %d) [%p] (the %d'th element)\n", 
name, i2_i, 
SETelemt_(set, i2_i, 
int), i2_i, 
SETelem_(set, i2_i), i2_i);