/*
- * $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
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;
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