]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
- Improved statHistInit() assertions for value_in/out functions. We used to
authorrousskov <>
Wed, 4 Mar 1998 13:23:28 +0000 (13:23 +0000)
committerrousskov <>
Wed, 4 Mar 1998 13:23:28 +0000 (13:23 +0000)
  '==' compare their (double) results with 0.0 which was not good.

src/StatHist.cc

index 6e4679ad78d9a8853d171273522dce1ff21650fb..da99cff2bce4e6cd6cbb364e7cedb0d554e2020a 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: StatHist.cc,v 1.3 1998/02/26 18:00:35 wessels Exp $
+ * $Id: StatHist.cc,v 1.4 1998/03/04 06:23:28 rousskov Exp $
  *
  * DEBUG: section 62    Generic Histogram
  * AUTHOR: Duane Wessels
@@ -58,8 +58,8 @@ statHistInit(StatHist * H, int capacity, hbase_f val_in, hbase_f val_out, double
     assert(H);
     assert(capacity > 0);
     assert(val_in && val_out);
-    /* check that functions are valid */
-    assert(val_in(0.0) == 0.0 && val_out(val_in(0.0)) == 0.0);
+    /* check before we divide to get scale */
+    assert(val_in(max - min) > 0);
     H->bins = xcalloc(capacity, sizeof(int));
     H->min = min;
     H->max = max;
@@ -67,6 +67,13 @@ statHistInit(StatHist * H, int capacity, hbase_f val_in, hbase_f val_out, double
     H->scale = capacity / val_in(max - min);
     H->val_in = val_in;
     H->val_out = val_out;
+    /* check that functions are valid */
+    /* a min value should go into bin[0] */
+    assert(statHistBin(H, min) == 0);
+    /* a max value should go into the last bin */
+    assert(statHistBin(H, max) == H->capacity - 1);
+    /* it is hard to test val_out, here is a crude test */
+    assert(((int)(0.99+statHistVal(H, 0)-min)) == 0);
 }
 
 void