IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 7, 2008, 1:12:13 PM (18 years ago)
Author:
eugene
Message:

various test fixes and cleanups

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/math/tap_psHistogram.c

    r17529 r17567  
    55    psVectorHistogram(): uniform histograms
    66    psVectorHistogram(): generic histograms
    7  *****************************************************************************/
     7*****************************************************************************/
    88#include <stdio.h>
    99#include <string.h>
     
    6767        for (int i=0;i<numBins+1;i++) {
    6868            myBounds->data.F32[i] = lower + ((higher - lower) / (float) numBins) *
    69                                     (float) i;
     69                (float) i;
    7070        }
    7171        psHistogram *myHist = psHistogramAllocGeneric(myBounds);
     
    134134        skip_start(myHist == NULL, 1, "Skipping tests because psVectorHistogram() returned NULL");
    135135
    136         // we need to explicitly count the number in each bin.  we can fool ourselves with rounding
    137         // otherwise
    138 
    139136        bool errorFlag = false;
    140137        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            }
    156156        }
    157157        ok(!errorFlag, "psVectorHistogram() correctly set the histogram");
     
    189189        bool errorFlag = false;
    190190        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            }
    208209        }
    209210        ok(!errorFlag, "psVectorHistogram() correctly set the histogram");
     
    226227        }
    227228        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");
    229230        psFree(myData);
    230231        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    239240        psHistogram *myHist = psHistogramAlloc(lower, higher, numBins);
    240241        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");
    242243        psFree(myHist);
    243244        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    253254        psHistogram *myHist = psHistogramAlloc(lower, higher, numBins);
    254255        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");
    256257        psFree(myHist);
    257258        psFree(myData);
     
    301302        skip_start(rc == false, 1, "Skipping tests because psVectorHistogram() returned FALSE");
    302303        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) {
    305315                diag("Bin number %d bounds: (%.2f - %.2f): data: (%.2f) should be (%.2f)\n", i,
    306316                     myHist->bounds->data.F32[i],
    307317                     myHist->bounds->data.F32[i+1],
    308                      myHist->nums->data.F32[i], expected);
     318                     myHist->nums->data.F32[i], nValues);
    309319                errorFlag = true;
    310320            }
    311321        }
    312         ok(!errorFlag, "psVectorHistogram() correctly initialized the bins");
     322        ok(!errorFlag, "psVectorHistogram() correctly set the bins");
    313323        skip_end();
    314324        psFree(myData);
Note: See TracChangeset for help on using the changeset viewer.