Index: trunk/psLib/test/math/tap_psHistogram.c
===================================================================
--- trunk/psLib/test/math/tap_psHistogram.c	(revision 17529)
+++ trunk/psLib/test/math/tap_psHistogram.c	(revision 17567)
@@ -5,5 +5,5 @@
     psVectorHistogram(): uniform histograms
     psVectorHistogram(): generic histograms
- *****************************************************************************/
+*****************************************************************************/
 #include <stdio.h>
 #include <string.h>
@@ -67,5 +67,5 @@
         for (int i=0;i<numBins+1;i++) {
             myBounds->data.F32[i] = lower + ((higher - lower) / (float) numBins) *
-                                    (float) i;
+		(float) i;
         }
         psHistogram *myHist = psHistogramAllocGeneric(myBounds);
@@ -134,24 +134,24 @@
         skip_start(myHist == NULL, 1, "Skipping tests because psVectorHistogram() returned NULL");
 
-	// we need to explicitly count the number in each bin.  we can fool ourselves with rounding
-	// otherwise
-
         bool errorFlag = false;
         for (int i = 0; i < numBins; i++) {
-	  int nValues = 0;
-	  for (int j = 0; j < myData->n; j++) {
-	    // XXX EAM : need to get rules right.  which boundary is inclusive, which is exclusive?
-	    if (myData->data.F32[j] <= myHist->bounds->data.F32[i]) continue;
-	    if (myData->data.F32[j] > myHist->bounds->data.F32[i+1]) continue;
-	    nValues ++;
-	  }
-	  if (myHist->nums->data.F32[i] != nValues) {
-	    diag("Bin number %d bounds: (%.2f - %.2f) data (%.2f) should be (%2d)\n",
-		 i,
-		 myHist->bounds->data.F32[i],
-		 myHist->bounds->data.F32[i+1],
-		 myHist->nums->data.F32[i], nValues);
-	    errorFlag = true;
-	  }
+
+	    // we need to explicitly count the number in each bin.  we can fool ourselves with
+	    // rounding otherwise
+	    int nValues = 0;
+	    for (int j = 0; j < myData->n; j++) {
+		// valid bin: bound[bin] <= value < bound[bin+1]
+		if (myData->data.F32[j] < myHist->bounds->data.F32[i]) continue;
+		if (myData->data.F32[j] >= myHist->bounds->data.F32[i+1]) continue;
+		nValues ++;
+	    }
+	    if (myHist->nums->data.F32[i] != nValues) {
+		diag("Bin number %d bounds: (%.2f - %.2f) data (%.2f) should be (%2d)\n",
+		     i,
+		     myHist->bounds->data.F32[i],
+		     myHist->bounds->data.F32[i+1],
+		     myHist->nums->data.F32[i], nValues);
+		errorFlag = true;
+	    }
         }
         ok(!errorFlag, "psVectorHistogram() correctly set the histogram");
@@ -189,21 +189,22 @@
         bool errorFlag = false;
         for (int i = 0;i < numBins;i++) {
-            if (i < numBins/2) {
-                if (fabs(myHist->nums->data.F32[i] - (NUM_DATA/numBins)) > ERROR_TOLERANCE) {
-                    diag("Bin number %d bounds: (%6.3f - %6.3f) data (%f) should be (%.2f)\n", i,
-                         myHist->bounds->data.F32[i],
-                         myHist->bounds->data.F32[i + 1],
-                         myHist->nums->data.F32[i], (float) (NUM_DATA/numBins));
-                    errorFlag = true;
-                }
-            } else {
-                if (fabs(myHist->nums->data.F32[i]) > ERROR_TOLERANCE) {
-                    diag("Bin number %d bounds: (%6.3f - %6.3f) data (%f) should be (%.2f)\n", i,
-                         myHist->bounds->data.F32[i],
-                         myHist->bounds->data.F32[i + 1],
-                         myHist->nums->data.F32[i], 0.0);
-                    errorFlag = true;
-                }
-            }
+
+	    // we need to explicitly count the number in each bin.  we can fool ourselves with
+	    // rounding otherwise
+	    int nValues = 0;
+	    for (int j = 0; j < myData->n; j++) {
+		// valid bin: bound[bin] <= value < bound[bin+1]
+		if (myMask->data.U8[j] == 1) continue;
+		if (myData->data.F32[j] < myHist->bounds->data.F32[i]) continue;
+		if (myData->data.F32[j] >= myHist->bounds->data.F32[i+1]) continue;
+		nValues ++;
+	    }
+	    if (myHist->nums->data.F32[i] != nValues) {
+		diag("Bin number %d bounds: (%6.3f - %6.3f) data (%f) should be (%.2f)\n", i,
+		     myHist->bounds->data.F32[i],
+		     myHist->bounds->data.F32[i + 1],
+		     myHist->nums->data.F32[i], (float) (NUM_DATA/numBins));
+		errorFlag = true;
+	    }
         }
         ok(!errorFlag, "psVectorHistogram() correctly set the histogram");
@@ -226,5 +227,5 @@
         }
         ok(false == psVectorHistogram(NULL, myData, NULL, NULL, 0),
-          "psVectorHistogram() returned FALSE with a NULL psHistogram input");
+	   "psVectorHistogram() returned FALSE with a NULL psHistogram input");
         psFree(myData);
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
@@ -239,5 +240,5 @@
         psHistogram *myHist = psHistogramAlloc(lower, higher, numBins);
         ok(true == psVectorHistogram(myHist, NULL, NULL, NULL, 0),
-          "psVectorHistogram() returns TRUE with a NULL input array");
+	   "psVectorHistogram() returns TRUE with a NULL input array");
         psFree(myHist);
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
@@ -253,5 +254,5 @@
         psHistogram *myHist = psHistogramAlloc(lower, higher, numBins);
         ok(true == psVectorHistogram(myHist, NULL, NULL, NULL, 0),
-          "psVectorHistogram() returns TRUE with an empty input array");
+	   "psVectorHistogram() returns TRUE with an empty input array");
         psFree(myHist);
         psFree(myData);
@@ -301,14 +302,23 @@
         skip_start(rc == false, 1, "Skipping tests because psVectorHistogram() returned FALSE");
         for (int i=0;i<numBins;i++) {
-            psF32 expected = ((float) NUM_DATA) / ((float) numBins);
-            if (fabs(myHist->nums->data.F32[i] - expected) > ERROR_TOLERANCE) {
+
+	    // we need to explicitly count the number in each bin.  we can fool ourselves with
+	    // rounding otherwise
+	    int nValues = 0;
+	    for (int j = 0; j < myData->n; j++) {
+		// valid bin: bound[bin] <= value < bound[bin+1]
+		if (myData->data.F32[j] < myHist->bounds->data.F32[i]) continue;
+		if (myData->data.F32[j] >= myHist->bounds->data.F32[i+1]) continue;
+		nValues ++;
+	    }
+	    if (myHist->nums->data.F32[i] != nValues) {
                 diag("Bin number %d bounds: (%.2f - %.2f): data: (%.2f) should be (%.2f)\n", i,
                      myHist->bounds->data.F32[i],
                      myHist->bounds->data.F32[i+1],
-                     myHist->nums->data.F32[i], expected);
+                     myHist->nums->data.F32[i], nValues);
                 errorFlag = true;
             }
         }
-        ok(!errorFlag, "psVectorHistogram() correctly initialized the bins");
+        ok(!errorFlag, "psVectorHistogram() correctly set the bins");
         skip_end();
         psFree(myData);
