Changeset 17567 for trunk/psLib/test/math/tap_psHistogram.c
- Timestamp:
- May 7, 2008, 1:12:13 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/math/tap_psHistogram.c (modified) (8 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);
Note:
See TracChangeset
for help on using the changeset viewer.
