From: rousskov <> Date: Wed, 4 Mar 1998 13:23:28 +0000 (+0000) Subject: - Improved statHistInit() assertions for value_in/out functions. We used to X-Git-Tag: SQUID_3_0_PRE1~3934 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f266e7af3d4802372ddb7eb68f238d086e0ad41;p=thirdparty%2Fsquid.git - Improved statHistInit() assertions for value_in/out functions. We used to '==' compare their (double) results with 0.0 which was not good. --- diff --git a/src/StatHist.cc b/src/StatHist.cc index 6e4679ad78..da99cff2bc 100644 --- a/src/StatHist.cc +++ b/src/StatHist.cc @@ -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