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);
168 vfprintf(fp, fmt, args);
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);
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){
784 qh_fprintf(stderr, 6344,
"%s: qh_setendpointer(), 0x%x, is not NULL terminator of set 0x%x", name,
qh_setendpointer(
set),
set);
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);
void qh_settempfree_all(void)
void qh_settruncate(setT *set, int size)
void qh_fprintf(FILE *fp, int msgcode, const char *fmt,...)
void qh_setappend2ndlast(setT **setp, void *newelem)
#define FOREACHint_i_(ints)
void testSetappendSettruncate(int numInts, int *intarray, int checkEvery)
void qh_setcompact(setT *set)
void qh_setreplace(setT *set, void *oldelem, void *newelem)
void setupMemory(int tracelevel, int numInts, int **intarray)
#define SETfirstt_(set, type)
void qh_setcheck(setT *set, const char *tname, unsigned id)
void qh_setaddsorted(setT **setp, void *newelem)
int main(int argc, char **argv)
int qh_setindex(setT *set, void *atelem)
void * qh_setdelnthsorted(setT *set, int nth)
void readOptions(int argc, char **argv, const char *promptstr, int *numInts, int *checkEvery, int *traceLevel)
setT * qh_settemppop(void)
int qh_setin(setT *set, void *setelem)
int qh_setequal_except(setT *setA, void *skipelemA, setT *setB, void *skipelemB)
void testSettemp(int numInts, int *intarray, int checkEvery)
void qh_meminitbuffers(int tracelevel, int alignment, int numsizes, int bufsize, int bufinit)
void qh_errexit(int exitcode, void *f, void *r)
void testSetcompactCopy(int numInts, int *intarray, int checkEvery)
void * qh_setlast(setT *set)
void qh_settempfree(setT **set)
void qh_setappend_set(setT **setp, setT *setA)
void testSetlastEtc(int numInts, int *intarray, int checkEvery)
void qh_exit(int exitcode)
#define SETelemaddr_(set, n, type)
void qh_memsize(int size)
setT * qh_setnew_delnthsorted(setT *set, int size, int nth, int prepend)
void qh_settemppush(setT *set)
void * qh_setdelnth(setT *set, int nth)
void qh_setzero(setT *set, int idx, int size)
#define SETreturnsize_(set, size)
#define FOREACHint_(ints)
void qh_setfree(setT **setp)
void qh_setaddnth(setT **setp, int nth, void *newelem)
#define SETelemt_(set, n, type)
#define SETindex_(set, elem)
void ** qh_setendpointer(setT *set)
void qh_setappend(setT **setp, void *newelem)
int log_i(setT *set, const char *s, int i, int numInts, int checkEvery)
void * qh_setdellast(setT *set)
void qh_memfreeshort(int *curlong, int *totlong)
void * qh_malloc(size_t size)
void testSetdelsortedEtc(int numInts, int *intarray, int checkEvery)
void * qh_setdelsorted(setT *set, void *oldelem)
void testSetappendSet(int numInts, int *intarray, int checkEvery)
#define SETtruncate_(set, size)
void * qh_setdel(setT *set, void *oldelem)
int qh_setunique(setT **set, void *elem)
void qh_fprintf_stderr(int msgcode, const char *fmt,...)
int qh_setequal_skip(setT *setA, int skipA, setT *setB, int skipB)
setT * qh_settemp(int setsize)
void qh_setfreelong(setT **setp)
void testSetequalInEtc(int numInts, int *intarray, int checkEvery)
void checkSetContents(const char *name, setT *set, int count, int rangeA, int rangeB, int rangeC)
void qh_meminit(FILE *ferr)
int qh_setequal(setT *setA, setT *setB)
int qh_setsize(setT *set)
setT * qh_setnew(int setsize)
void qh_memstatistics(FILE *fp)
void testSetdelSetadd(int numInts, int *intarray, int checkEvery)
void qh_setlarger(setT **oldsetp)
#define SETaddr_(set, type)
setT * qh_setcopy(setT *set, int extra)
#define SETsecondt_(set, type)