Changeset 17567
- Timestamp:
- May 7, 2008, 1:12:13 PM (18 years ago)
- Location:
- trunk/psLib/test/math
- Files:
-
- 5 edited
-
tap_psHistogram.c (modified) (8 diffs)
-
tap_psMatrix02.c (modified) (5 diffs)
-
tap_psPolyFit2D.c (modified) (2 diffs)
-
tap_psPolyFit3D.c (modified) (3 diffs)
-
tap_psPolyFit4D.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/math/tap_psHistogram.c
r17529 r17567 5 5 psVectorHistogram(): uniform histograms 6 6 psVectorHistogram(): generic histograms 7 *****************************************************************************/7 *****************************************************************************/ 8 8 #include <stdio.h> 9 9 #include <string.h> … … 67 67 for (int i=0;i<numBins+1;i++) { 68 68 myBounds->data.F32[i] = lower + ((higher - lower) / (float) numBins) * 69 (float) i;69 (float) i; 70 70 } 71 71 psHistogram *myHist = psHistogramAllocGeneric(myBounds); … … 134 134 skip_start(myHist == NULL, 1, "Skipping tests because psVectorHistogram() returned NULL"); 135 135 136 // we need to explicitly count the number in each bin. we can fool ourselves with rounding137 // otherwise138 139 136 bool errorFlag = false; 140 137 for (int i = 0; i < numBins; i++) { 141 int nValues = 0; 142 for (int j = 0; j < myData->n; j++) { 143 // XXX EAM : need to get rules right. which boundary is inclusive, which is exclusive? 144 if (myData->data.F32[j] <= myHist->bounds->data.F32[i]) continue; 145 if (myData->data.F32[j] > myHist->bounds->data.F32[i+1]) continue; 146 nValues ++; 147 } 148 if (myHist->nums->data.F32[i] != nValues) { 149 diag("Bin number %d bounds: (%.2f - %.2f) data (%.2f) should be (%2d)\n", 150 i, 151 myHist->bounds->data.F32[i], 152 myHist->bounds->data.F32[i+1], 153 myHist->nums->data.F32[i], nValues); 154 errorFlag = true; 155 } 138 139 // we need to explicitly count the number in each bin. we can fool ourselves with 140 // rounding otherwise 141 int nValues = 0; 142 for (int j = 0; j < myData->n; j++) { 143 // valid bin: bound[bin] <= value < bound[bin+1] 144 if (myData->data.F32[j] < myHist->bounds->data.F32[i]) continue; 145 if (myData->data.F32[j] >= myHist->bounds->data.F32[i+1]) continue; 146 nValues ++; 147 } 148 if (myHist->nums->data.F32[i] != nValues) { 149 diag("Bin number %d bounds: (%.2f - %.2f) data (%.2f) should be (%2d)\n", 150 i, 151 myHist->bounds->data.F32[i], 152 myHist->bounds->data.F32[i+1], 153 myHist->nums->data.F32[i], nValues); 154 errorFlag = true; 155 } 156 156 } 157 157 ok(!errorFlag, "psVectorHistogram() correctly set the histogram"); … … 189 189 bool errorFlag = false; 190 190 for (int i = 0;i < numBins;i++) { 191 if (i < numBins/2) { 192 if (fabs(myHist->nums->data.F32[i] - (NUM_DATA/numBins)) > ERROR_TOLERANCE) { 193 diag("Bin number %d bounds: (%6.3f - %6.3f) data (%f) should be (%.2f)\n", i, 194 myHist->bounds->data.F32[i], 195 myHist->bounds->data.F32[i + 1], 196 myHist->nums->data.F32[i], (float) (NUM_DATA/numBins)); 197 errorFlag = true; 198 } 199 } else { 200 if (fabs(myHist->nums->data.F32[i]) > ERROR_TOLERANCE) { 201 diag("Bin number %d bounds: (%6.3f - %6.3f) data (%f) should be (%.2f)\n", i, 202 myHist->bounds->data.F32[i], 203 myHist->bounds->data.F32[i + 1], 204 myHist->nums->data.F32[i], 0.0); 205 errorFlag = true; 206 } 207 } 191 192 // we need to explicitly count the number in each bin. we can fool ourselves with 193 // rounding otherwise 194 int nValues = 0; 195 for (int j = 0; j < myData->n; j++) { 196 // valid bin: bound[bin] <= value < bound[bin+1] 197 if (myMask->data.U8[j] == 1) continue; 198 if (myData->data.F32[j] < myHist->bounds->data.F32[i]) continue; 199 if (myData->data.F32[j] >= myHist->bounds->data.F32[i+1]) continue; 200 nValues ++; 201 } 202 if (myHist->nums->data.F32[i] != nValues) { 203 diag("Bin number %d bounds: (%6.3f - %6.3f) data (%f) should be (%.2f)\n", i, 204 myHist->bounds->data.F32[i], 205 myHist->bounds->data.F32[i + 1], 206 myHist->nums->data.F32[i], (float) (NUM_DATA/numBins)); 207 errorFlag = true; 208 } 208 209 } 209 210 ok(!errorFlag, "psVectorHistogram() correctly set the histogram"); … … 226 227 } 227 228 ok(false == psVectorHistogram(NULL, myData, NULL, NULL, 0), 228 "psVectorHistogram() returned FALSE with a NULL psHistogram input");229 "psVectorHistogram() returned FALSE with a NULL psHistogram input"); 229 230 psFree(myData); 230 231 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); … … 239 240 psHistogram *myHist = psHistogramAlloc(lower, higher, numBins); 240 241 ok(true == psVectorHistogram(myHist, NULL, NULL, NULL, 0), 241 "psVectorHistogram() returns TRUE with a NULL input array");242 "psVectorHistogram() returns TRUE with a NULL input array"); 242 243 psFree(myHist); 243 244 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); … … 253 254 psHistogram *myHist = psHistogramAlloc(lower, higher, numBins); 254 255 ok(true == psVectorHistogram(myHist, NULL, NULL, NULL, 0), 255 "psVectorHistogram() returns TRUE with an empty input array");256 "psVectorHistogram() returns TRUE with an empty input array"); 256 257 psFree(myHist); 257 258 psFree(myData); … … 301 302 skip_start(rc == false, 1, "Skipping tests because psVectorHistogram() returned FALSE"); 302 303 for (int i=0;i<numBins;i++) { 303 psF32 expected = ((float) NUM_DATA) / ((float) numBins); 304 if (fabs(myHist->nums->data.F32[i] - expected) > ERROR_TOLERANCE) { 304 305 // we need to explicitly count the number in each bin. we can fool ourselves with 306 // rounding otherwise 307 int nValues = 0; 308 for (int j = 0; j < myData->n; j++) { 309 // valid bin: bound[bin] <= value < bound[bin+1] 310 if (myData->data.F32[j] < myHist->bounds->data.F32[i]) continue; 311 if (myData->data.F32[j] >= myHist->bounds->data.F32[i+1]) continue; 312 nValues ++; 313 } 314 if (myHist->nums->data.F32[i] != nValues) { 305 315 diag("Bin number %d bounds: (%.2f - %.2f): data: (%.2f) should be (%.2f)\n", i, 306 316 myHist->bounds->data.F32[i], 307 317 myHist->bounds->data.F32[i+1], 308 myHist->nums->data.F32[i], expected);318 myHist->nums->data.F32[i], nValues); 309 319 errorFlag = true; 310 320 } 311 321 } 312 ok(!errorFlag, "psVectorHistogram() correctly initializedthe bins");322 ok(!errorFlag, "psVectorHistogram() correctly set the bins"); 313 323 skip_end(); 314 324 psFree(myData); -
trunk/psLib/test/math/tap_psMatrix02.c
r13124 r17567 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $15 * @date $Date: 200 7-05-02 04:20:06$14 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2008-05-07 23:12:13 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 28 28 { 29 29 psLogSetFormat("HLNM"); 30 plan_tests( 11);30 plan_tests(23); 31 31 32 32 // Input pointer same as output pointer … … 34 34 // a requirement. However, we should probably fix the case where the input 35 35 // image equals the output image. 36 if (0){36 { 37 37 psMemId id = psMemGetId(); 38 38 psImage *inImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64); 39 ok(psMatrixTranspose(inImage, inImage) == NULL, "psMatrixTranspose(): inImage = outImage results in NULL"); 40 ok(psMemGetRefCounter(inImage) == 1, "psMatrixTranspose(): the output image was freed on an error."); 39 ok(psMatrixTranspose(inImage, inImage) == NULL, "psMatrixTranspose(): inImage == outImage results in NULL"); 41 40 psFree(inImage); 42 41 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); … … 50 49 psImage *nullImage = NULL; 51 50 psImage *outImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64); 52 psMemIncrRefCounter(outImage);53 51 ok(psMatrixTranspose(outImage, nullImage) == NULL, "psMatrixTranspose(): inImage = NULL results in NULL return"); 54 ok(psMemGetRefCounter(outImage) == 1, "psMatrixTranspose(): the output image was freed on an error.");55 52 psFree(outImage); 56 53 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 57 54 } 58 55 59 60 56 // Incorrect type for input pointer 61 // Merge with tap_psMatrix01.c, get rid of this test (redundant)62 57 { 63 58 psMemId id = psMemGetId(); 59 psImage *inImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_U8); 64 60 psImage *outImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64); 65 psImage *badImage1 = (psImage*)psImageAlloc(3, 3, PS_TYPE_U8); 66 psMemIncrRefCounter(outImage); 67 ok(psMatrixTranspose(outImage, badImage1) == NULL, "psMatrixTranspose(): inImage = outImage results in NULL return"); 68 ok(psMemGetRefCounter(outImage) == 1, "the output image was freed on the error."); 61 ok(psMatrixTranspose(outImage, inImage) == NULL, "psMatrixTranspose(): inImage wrong type (U8) results in NULL return"); 69 62 psFree(outImage); 70 psFree( badImage1);63 psFree(inImage); 71 64 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 72 65 } 73 66 67 // Incorrect type for input pointer 68 { 69 psMemId id = psMemGetId(); 70 psImage *inImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_S32); 71 psImage *outImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64); 72 ok(psMatrixTranspose(outImage, inImage) == NULL, "psMatrixTranspose(): inImage wrong type (S32) results in NULL return"); 73 psFree(outImage); 74 psFree(inImage); 75 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 76 } 74 77 75 78 // Incorrect type for output pointer … … 77 80 psMemId id = psMemGetId(); 78 81 psImage *inImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64); 79 psImage *badImage1 = (psImage*)psImageAlloc(3, 3, PS_TYPE_U8); 80 badImage1 = psMatrixTranspose(badImage1, inImage); 81 ok(badImage1 != NULL, "psMatrixTranspose() results in non-NULL return"); 82 psImage *outImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_U8); 83 outImage = psMatrixTranspose(outImage, inImage); 84 ok(outImage != NULL, "psMatrixTranspose() results in non-NULL return"); 85 82 86 // check that the type was changed. 83 ok( badImage1->type.type == PS_TYPE_F64, "the output type was changed to F64");87 ok(outImage->type.type == PS_TYPE_F64, "the output type was changed to F64"); 84 88 psFree(inImage); 85 psFree( badImage1);89 psFree(outImage); 86 90 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 87 91 } 88 92 89 90 // Matrix not square for output pointer 91 // XXX: We should probably do more here. 93 // output target matrix not square (Nx > Ny) for output pointer 92 94 { 93 95 psMemId id = psMemGetId(); 94 96 psImage *inImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64); 95 psImage *badImage2 = (psImage*)psImageAlloc(3, 2, PS_TYPE_F64); 96 ok(psMatrixTranspose(badImage2, inImage) != NULL, "psMatrixTranspose(): non-square matrix results in non-NULL"); 97 psImage *outImage = (psImage*)psImageAlloc(3, 2, PS_TYPE_F64); 98 ok(psMatrixTranspose(outImage, inImage) != NULL, "psMatrixTranspose(): non-square matrix results in non-NULL"); 99 ok(outImage->numCols == 3, "psMatrixTranspose(): output matrix dimensions match input"); 100 ok(outImage->numRows == 3, "psMatrixTranspose(): output matrix dimensions match input"); 97 101 psFree(inImage); 98 psFree(badImage2); 102 psFree(outImage); 103 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 104 } 105 106 // input matrix not square (Nx < Ny) 107 { 108 psMemId id = psMemGetId(); 109 psImage *inImage = (psImage*)psImageAlloc(2, 3, PS_TYPE_F64); 110 psImage *outImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64); 111 ok(psMatrixTranspose(outImage, inImage) != NULL, "psMatrixTranspose(): non-square matrix results in non-NULL"); 112 ok(outImage->numCols == 3, "psMatrixTranspose(): output matrix dimensions match input"); 113 ok(outImage->numRows == 2, "psMatrixTranspose(): output matrix dimensions match input"); 114 psFree(inImage); 115 psFree(outImage); 116 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 117 } 118 119 // input matrix not square (Nx > Ny) 120 { 121 psMemId id = psMemGetId(); 122 psImage *inImage = (psImage*)psImageAlloc(3, 2, PS_TYPE_F64); 123 psImage *outImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64); 124 ok(psMatrixTranspose(outImage, inImage) != NULL, "psMatrixTranspose(): non-square matrix results in non-NULL"); 125 ok(outImage->numCols == 2, "psMatrixTranspose(): output matrix dimensions match input"); 126 ok(outImage->numRows == 3, "psMatrixTranspose(): output matrix dimensions match input"); 127 psFree(inImage); 128 psFree(outImage); 99 129 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 100 130 } -
trunk/psLib/test/math/tap_psPolyFit2D.c
r13337 r17567 424 424 psMemId id = psMemGetId(); 425 425 bool rc = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, xS32, y); 426 ok(rc == false, "psVectorFitPolynomial2D() returned FALSE: Set x vector to incorrect type");426 ok(rc == true, "psVectorFitPolynomial2D() returned TRUE: x vector may be S32"); 427 427 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 428 428 } … … 433 433 psMemId id = psMemGetId(); 434 434 bool rc = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, x, yS32); 435 ok(rc == false, "psVectorFitPolynomial2D() returned FALSE: Set y vector to incorrect type");435 ok(rc == true, "psVectorFitPolynomial2D() returned TRUE: y vector may be S32"); 436 436 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 437 437 } -
trunk/psLib/test/math/tap_psPolyFit3D.c
r13337 r17567 476 476 psMemId id = psMemGetId(); 477 477 bool rc = psVectorFitPolynomial3D(myPoly, mask, MASK_VALUE, f, fErr, xS32, y, z); 478 ok(rc == false, "psVectorFitPolynomial3D() returned FALSE: Set x vector to incorrect type");478 ok(rc == true, "psVectorFitPolynomial3D() returned TRUE: x vector may be S32"); 479 479 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 480 480 } … … 485 485 psMemId id = psMemGetId(); 486 486 bool rc = psVectorFitPolynomial3D(myPoly, mask, MASK_VALUE, f, fErr, x, yS32, z); 487 ok(rc == false, "psVectorFitPolynomial3D() returned FALSE: Set y vector to incorrect type");487 ok(rc == true, "psVectorFitPolynomial3D() returned TRUE: y vector may be S32"); 488 488 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 489 489 } … … 494 494 psMemId id = psMemGetId(); 495 495 bool rc = psVectorFitPolynomial3D(myPoly, mask, MASK_VALUE, f, fErr, x, y, zS32); 496 ok(rc == false, "psVectorFitPolynomial3D() returned FALSE: Set z vector to incorrect type");496 ok(rc == true, "psVectorFitPolynomial3D() returned TRUE: z vector may be S32"); 497 497 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 498 498 } -
trunk/psLib/test/math/tap_psPolyFit4D.c
r17515 r17567 536 536 psMemId id = psMemGetId(); 537 537 bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, xS32, y, z, t); 538 ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set x vector to incorrect type");538 ok(rc == true, "psVectorFitPolynomial4D() returned TRUE: x vector may be S32"); 539 539 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 540 540 } … … 545 545 psMemId id = psMemGetId(); 546 546 bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, yS32, z, t); 547 ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set y vector to incorrect type");547 ok(rc == true, "psVectorFitPolynomial4D() returned TRUE: y vector may be S32"); 548 548 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 549 549 } … … 554 554 psMemId id = psMemGetId(); 555 555 bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, zS32, t); 556 ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set z vector to incorrect type");556 ok(rc == true, "psVectorFitPolynomial4D() returned TRUE: z vector may be S32"); 557 557 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 558 558 } … … 563 563 psMemId id = psMemGetId(); 564 564 bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z, tS32); 565 ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set t vector to incorrect type");565 ok(rc == true, "psVectorFitPolynomial4D() returned TRUE: t vector may be S32"); 566 566 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 567 567 }
Note:
See TracChangeset
for help on using the changeset viewer.
