85 #define MAXerrorCount 100 87 #define FOREACHint_( ints ) FOREACHsetelement_( i2T, ints, i2) 88 #define FOREACHint4_( ints ) FOREACHsetelement_( i2T, ints, i4) 89 #define FOREACHint_i_( qh, ints ) FOREACHsetelement_i_( qh, i2T, ints, i2) 90 #define FOREACHintreverse_( qh, ints ) FOREACHsetelementreverse_( qh, i2T, ints, i2) 91 #define FOREACHintreverse12_( ints ) FOREACHsetelementreverse12_( i2T, ints, i2) 97 char prompt[]=
"testqset_r N [M] [T5] -- Test reentrant qset_r.c and mem_r.c\n\ 99 If this test fails then reentrant Qhull will not work.\n\ 101 Test qsets of 0..N integers with a check every M iterations (default ~log10)\n\ 102 Additional checking and logging if M is 1\n\ 104 T5 turns on memory logging (qset does not log)\n\ 113 #define fmax_( a,b ) ( ( a ) < ( b ) ? ( b ) : ( a ) ) 138 static int needs_cr= 0;
140 size_t fmtlen= strlen(fmt);
146 fprintf(stderr,
"QH6241 qh_fprintf: fp and qh not defined for '%s'", fmt);
148 fprintf(stderr,
"QH6232 qh_fprintf: fp is 0. Was wrong qh_fprintf called for '%s'", fmt);
152 if(fmt[fmtlen-1]==
'\n'){
153 if(needs_cr && fmtlen>1){
161 if(msgcode>=6000 && msgcode<7000){
162 fprintf(fp,
"Error TQ%d ", msgcode);
165 vfprintf(fp, fmt, args);
170 int main(
int argc,
char **argv);
171 void readOptions(
qhT *
qh,
int argc,
char **argv,
const char *promptstr,
int *numInts,
int *checkEvery,
int *traceLevel);
172 void setupMemory(
qhT *qh,
int tracelevel,
int numInts,
int **intarray);
179 void testSettemp(
qhT *qh,
int numInts,
int *intarray,
int checkEvery);
183 int log_i(
qhT *qh,
setT *
set,
const char *s,
int i,
int numInts,
int checkEvery);
186 int main(
int argc,
char **argv) {
190 int curlong, totlong;
195 #if defined(_MSC_VER) && defined(_DEBUG) && defined(QHULL_CRTDBG) 196 _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) );
197 _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG );
198 _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR );
212 printf(
"\n\nNot testing qh_setduplicate and qh_setfree2.\n These routines use heap-allocated set contents. See qhull tests.\n");
216 if (curlong || totlong){
217 qh_fprintf(qh, stderr, 8043,
"qh_memfreeshort: did not free %d bytes of long memory(%d pieces)\n", totlong, curlong);
224 printf(
"testqset_r: OK\n\n");
229 void readOptions(
qhT *qh,
int argc,
char **argv,
const char *promptstr,
int *numInts,
int *checkEvery,
int *traceLevel)
236 if (argc < 2 || argc > 4) {
237 printf(
"%s", promptstr);
240 numIntsArg= strtol(argv[1], &endp, 10);
242 qh_fprintf(qh, stderr, 6301,
"First argument should be 1 or greater. Got '%s'\n", argv[1]);
246 qh_fprintf(qh, stderr, 6302,
"qset does not currently support 64-bit ints. Maximum count is %d\n",
MAXint);
249 *numInts= (int)numIntsArg;
251 if(argc==3 && argv[2][0]==
'T' && argv[2][1]==
'5' ){
255 if(argc==4 || (argc==3 && !isTracing)){
256 checkEveryArg= strtol(argv[2], &endp, 10);
258 qh_fprintf(qh, stderr, 6321,
"checkEvery argument should be 1 or greater. Got '%s'\n", argv[2]);
262 qh_fprintf(qh, stderr, 6322,
"qset does not currently support 64-bit ints. Maximum checkEvery is %d\n",
MAXint);
266 if(argv[3][0]==
'T' && argv[3][1]==
'5' ){
270 qh_fprintf(qh, stderr, 6242,
"Optional third argument must be 'T5'. Got '%s'\n", argv[3]);
274 *checkEvery= (int)checkEveryArg;
281 if(numInts<0 || numInts*(
int)
sizeof(
int)<0){
282 qh_fprintf(qh, stderr, 6303,
"qset does not currently support 64-bit ints. Integer overflow\n");
285 *intarray=
qh_malloc(numInts *
sizeof(
int));
287 qh_fprintf(qh, stderr, 6304,
"Failed to allocate %d bytes of memory\n", numInts *
sizeof(
int));
290 for(i= 0; i<numInts; i++){
310 qh_fprintf(qh, stderr, 8002,
"\n\nTesting qh_setappend 0..%d. Test", numInts-1);
311 for(i= 0; i<numInts; i++){
312 isCheck=
log_i(qh, ints,
"i", i, numInts, checkEvery);
319 qh_fprintf(qh, stderr, 8014,
"\n\nTesting qh_settruncate %d and 0. Test", numInts/2);
321 isCheck=
log_i(qh, ints,
"n", numInts/2, numInts, checkEvery);
325 isCheck=
log_i(qh, ints,
"n", 0, numInts, checkEvery);
329 qh_fprintf(qh, stderr, 8003,
"\n\nTesting qh_setappend2ndlast 0,0..%d. Test 0", numInts-1);
333 for(i= 0; i<numInts; i++){
334 isCheck=
log_i(qh, ints,
"i", i, numInts, checkEvery);
340 qh_fprintf(qh, stderr, 8015,
"\n\nTesting SETtruncate_ %d and 0. Test", numInts/2);
342 isCheck=
log_i(qh, ints,
"n", numInts/2, numInts, checkEvery);
346 isCheck=
log_i(qh, ints,
"n", 0, numInts, checkEvery);
358 qh_fprintf(qh, stderr, 8003,
"\n\nTesting qh_setdelnthsorted and qh_setaddnth 1..%d. Test", numInts-1);
359 for(j=1; j<numInts; j++){
365 for(i= 0; i<j && i<100; i++){
366 isCheck=
log_i(qh, ints,
"", i, numInts, checkEvery);
371 checkSetContents(qh,
"qh_setdelnthsorted qh_setaddnth", ints, j, 0, -1, -1);
374 checkSetContents(qh,
"qh_setdelnthsorted qh_setaddnth 2", ints, j, 0, -1, -1);
386 qh_fprintf(qh, stderr, 8016,
"\n\nTesting qh_setappend_set 0..%d. Test", numInts-1);
387 for(j=0; j<numInts; j++){
388 if(
log_i(qh, ints,
"j", j, numInts, numInts)){
396 for(i= 0; i<=j && i<=20; i++){
397 if(
log_i(qh, ints,
"", i, numInts, numInts)){
405 checkSetContents(qh,
"qh_setappend_set", ints, i+j, 0, (j==0 ? -1 : 0), -1);
424 qh_fprintf(qh, stderr, 8017,
"\n\nTesting qh_setcompact and qh_setcopy 0..%d. Test", numInts-1);
425 for(j=0; j<numInts; j++){
426 if(
log_i(qh, ints,
"j", j, numInts, checkEvery)){
428 for(k= 0; k<i%7; k++){
453 qh_fprintf(qh, stderr, 8018,
"\n\nTesting qh_setdel*, qh_setaddsorted, and 0..%d. Test", numInts-1);
454 for(j=0; j<numInts; j++){
455 if(
log_i(qh, ints,
"j", j, numInts, checkEvery)){
509 qh_fprintf(qh, stderr, 8019,
"\n\nTesting qh_setequal*, qh_setin*, qh_setdel, qh_setdelnth, and qh_setlarger 0..%d. Test", numInts-1);
510 for(j=0; j<numInts; j++){
511 if(
log_i(qh, ints,
"j", j, numInts, checkEvery)){
520 qh_fprintf(qh, stderr, 6300,
"testSetequalInEtc: set not equal to itself at length %d\n", j);
524 qh_fprintf(qh, stderr, 6323,
"testSetequalInEtc: empty set not equal to null set\n");
529 qh_fprintf(qh, stderr, 6324,
"testSetequalInEtc: non-empty set equal to empty set\n", j);
544 qh_fprintf(qh, stderr, 6325,
"testSetequalInEtc: modified set equal to original set at %d/2\n", j);
548 qh_fprintf(qh, stderr, 6326,
"qh_setequal_except: modified set not equal to original set except modified\n", j);
552 qh_fprintf(qh, stderr, 6327,
"qh_setequal_except: modified set equal to original set with wrong excepts\n", j);
556 qh_fprintf(qh, stderr, 6328,
"qh_setequal_skip: modified set not equal to original set except modified\n", j);
560 qh_fprintf(qh, stderr, 6329,
"qh_setequal_skip: modified set equal to original set with wrong excepts\n", j);
563 if(intarray+j/2+1!=
qh_setdel(ints3, intarray+j/2+1)){
564 qh_fprintf(qh, stderr, 6330,
"qh_setdel: failed to find added element\n", j);
570 checkSetContents(qh,
"qh_setdelnth", ints3, j-2, 0, j-2, (j==2 ? -1 : j/2+1));
573 qh_fprintf(qh, stderr, 6331,
"qh_setin: found deleted element\n");
576 if(j>4 && !
qh_setin(ints3, intarray+1)){
577 qh_fprintf(qh, stderr, 6332,
"qh_setin: did not find second element\n");
580 if(j>4 && !
qh_setin(ints3, intarray+j-2)){
581 qh_fprintf(qh, stderr, 6333,
"qh_setin: did not find last element\n");
585 qh_fprintf(qh, stderr, 6334,
"qh_setindex: found element in empty set\n");
589 qh_fprintf(qh, stderr, 6335,
"qh_setindex: found deleted element in set\n");
593 qh_fprintf(qh, stderr, 6336,
"qh_setindex: did not find first in set\n");
597 qh_fprintf(qh, stderr, 6337,
"qh_setindex: did not find last in set\n");
618 qh_fprintf(qh, stderr, 8020,
"\n\nTesting qh_setlast, qh_setnew_delnthsorted, qh_setunique, and qh_setzero 0..%d. Test", numInts-1);
619 for(j=0; j<numInts; j++){
620 if(
log_i(qh, ints,
"j", j, numInts, checkEvery)){
623 qh_fprintf(qh, stderr, 6340,
"qh_setunique: not able to append next element %d\n", i);
630 qh_fprintf(qh, stderr, 6341,
"qh_setunique: appended next element twice %d\n", i);
634 qh_fprintf(qh, stderr, 6346,
"qh_setunique: appended middle element twice %d/2\n", i);
640 qh_fprintf(qh, stderr, 6339,
"qh_setlast: returned last element of empty set\n");
645 qh_fprintf(qh, stderr, 6338,
"qh_setlast: wrong last element\n");
648 prepend= (j<100 ? j/4 : 0);
651 qh_fprintf(qh, stderr, 6345,
"qh_setnew_delnthsorted: Expecting %d elements, got %d\n", j+prepend-1,
qh_setsize(qh, ints2));
655 for(i= 0; i<prepend; i++){
659 for(i= 0; i<prepend; i++){
666 qh_fprintf(qh, stderr, 6342,
"qh_setzero: Expecting %d elements, got %d\n", j,
qh_setsize(qh, ints2));
689 qh_fprintf(qh, stderr, 8021,
"\n\nTesting qh_settemp* 0..%d. Test", numInts-1);
690 for(j=0; j<numInts; j++){
691 if(
log_i(qh, ints,
"j", j, numInts, checkEvery)){
706 qh_fprintf(qh, stderr, 6343,
"qh_settemppop: didn't pop the push\n");
724 int log_i(
qhT *qh,
setT *
set,
const char *s,
int i,
int numInts,
int checkEvery)
731 if(*s || checkEvery==1){
735 if(i==11 && checkEvery==1){
736 qh_fprintf(qh, stderr, 8005,
"\nResults after 10: ");
752 qh_fprintf(qh, stderr, 8009,
" %s1e%d", s, e);
757 if(i<1000 || i%checkEvery==0 || i== scale || i==numInts-1){
783 qh_fprintf(qh, stderr, 6344,
"%s: qh_setendpointer(set), 0x%x, is not NULL terminator of set 0x%x", name,
qh_setendpointer(
set),
set);
788 qh_fprintf(qh, stderr, 6305,
"%s: SETreturnsize_(qh) returned %d while qh_setsize(qh) returns %d\n", name, actualSize,
qh_setsize(qh,
set));
790 }
else if(actualSize!=count){
791 qh_fprintf(qh, stderr, 6306,
"%s: Expecting %d elements for set. Got %d elements\n", name, count, actualSize);
796 qh_fprintf(qh, stderr, 6307,
"%s: Got empty set instead of count %d, rangeA %d, rangeB %d, rangeC %d\n", name, count, rangeA, rangeB, rangeC);
827 qh_fprintf(qh, stderr, 6311,
"%s: Expecting SETindex_(set, pointer-to-%d) to be %d. Got %d\n", name, *i2, i,
SETindex_(
set, i2));
831 qh_fprintf(qh, stderr, 6312,
"%s: SETref_(i2) [%p] does not point to i2 (the %d'th element)\n", name,
SETref_(i2), i);
840 qh_fprintf(qh, stderr, 6320,
"%s: SETelemaddr_(set, %d, i2T) [%p] does not point to i2\n", name, i2_i,
SETelemaddr_(
set, i2_i,
int));
845 qh_fprintf(qh, stderr, 6314,
"%s: First element is %d instead of SETfirst %d\n", name, *i2, first);
849 qh_fprintf(qh, stderr, 6315,
"%s: starts with %d instead of rangeA %d\n", name, *i2, rangeA);
854 if(i2_i==1 && second!=*i2){
855 qh_fprintf(qh, stderr, 6316,
"%s: Second element is %d instead of SETsecond %d\n", name, *i2, second);
865 }
else if(rangeB==-1 && *i2==rangeC){
871 qh_fprintf(qh, stderr, 6317,
"%s: Expecting %d'th element to be %d. Got %d\n", name, i2_i, prev, *i2);
877 qh_fprintf(qh, 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);
881 qh_fprintf(qh, 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_exit(int exitcode)
void testSetdelSetadd(qhT *qh, int numInts, int *intarray, int checkEvery)
void qh_settruncate(setT *set, int size)
void qh_setappend2ndlast(setT **setp, void *newelem)
void qh_setcompact(setT *set)
void qh_setreplace(setT *set, void *oldelem, void *newelem)
#define SETfirstt_(set, type)
void qh_setcheck(setT *set, const char *tname, unsigned id)
void setupMemory(qhT *qh, int tracelevel, int numInts, int **intarray)
void qh_setaddsorted(setT **setp, void *newelem)
void testSetappendSet(qhT *qh, int numInts, int *intarray, int checkEvery)
int main(int argc, char **argv)
int qh_setindex(setT *set, void *atelem)
void * qh_setdelnthsorted(setT *set, int nth)
void qh_fprintf(qhT *qh, FILE *fp, int msgcode, const char *fmt,...)
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(qhT *qh, int numInts, int *intarray, int checkEvery)
void qh_meminitbuffers(int tracelevel, int alignment, int numsizes, int bufsize, int bufinit)
void * qh_malloc(size_t size)
void * qh_setlast(setT *set)
void qh_settempfree(setT **set)
void qh_setappend_set(setT **setp, setT *setA)
#define SETelemaddr_(set, n, type)
void qh_memsize(int size)
setT * qh_setnew_delnthsorted(setT *set, int size, int nth, int prepend)
void testSetappendSettruncate(qhT *qh, int numInts, int *intarray, int checkEvery)
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)
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 readOptions(qhT *qh, int argc, char **argv, const char *promptstr, int *numInts, int *checkEvery, int *traceLevel)
void qh_setappend(setT **setp, void *newelem)
void * qh_setdellast(setT *set)
void testSetlastEtc(qhT *qh, int numInts, int *intarray, int checkEvery)
void testSetdelsortedEtc(qhT *qh, int numInts, int *intarray, int checkEvery)
void qh_memfreeshort(int *curlong, int *totlong)
void * qh_setdelsorted(setT *set, void *oldelem)
void testSetequalInEtc(qhT *qh, int numInts, int *intarray, int checkEvery)
#define SETtruncate_(set, size)
void * qh_setdel(setT *set, void *oldelem)
int qh_setunique(setT **set, void *elem)
int qh_setequal_skip(setT *setA, int skipA, setT *setB, int skipB)
setT * qh_settemp(int setsize)
void qh_setfreelong(setT **setp)
void qh_errexit(qhT *qh, int exitcode, facetT *f, ridgeT *r)
#define FOREACHint_(ints)
void qh_meminit(FILE *ferr)
void checkSetContents(qhT *qh, const char *name, setT *set, int count, int rangeA, int rangeB, int rangeC)
int qh_setequal(setT *setA, setT *setB)
int qh_setsize(setT *set)
setT * qh_setnew(int setsize)
void qh_memstatistics(FILE *fp)
void testSetcompactCopy(qhT *qh, int numInts, int *intarray, int checkEvery)
void qh_setlarger(setT **oldsetp)
#define SETaddr_(set, type)
void qh_fprintf_stderr(int msgcode, const char *fmt,...)
int log_i(qhT *qh, setT *set, const char *s, int i, int numInts, int checkEvery)
#define FOREACHint_i_(qh, ints)
setT * qh_setcopy(setT *set, int extra)
#define SETsecondt_(set, type)