%description:
cHistogram and various setRange() methods

%includes:
#include <iomanip>

%activity:

#if defined(__clang__) || defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif

const int FIRSTVALS=100;
const double RANGEEXT=1.5;

cHistogram if_("int-fixed");
cHistogram ia ("int-auto");
cHistogram iau("int-autoupper");
cHistogram ial("int-autolower");

cHistogram ian("int-auto-5cell");
cHistogram ifn("int-fixed-5cell");
cHistogram iaun("int-autoupper-5cell");
cHistogram ialn("int-autolower-5cell");

cVarHistogram iva("int-varhist-auto");

cHistogram df_("double-fixed");
cHistogram da ("double-auto");
cHistogram dau("double-autoupper");
cHistogram dal("double-autolower");

cHistogram dan("double-auto-5cell");
cHistogram dfn("double-fixed-5cell");
cHistogram daun("double-autoupper-5cell");
cHistogram daln("double-autolower-5cell");

cVarHistogram dva("double-varhist-auto");
cKSplit ksa("double-ksplit-auto");
cPSquare psq("double-psquare");

if_.setRange(10, 20); if_.setMode(cHistogram::MODE_INTEGERS); // mode is not auto-selected, because transform happens immediately (FIXME is that good?)
ia.setRangeAuto(FIRSTVALS, RANGEEXT);
iau.setRangeAutoUpper(10, FIRSTVALS, RANGEEXT);
ial.setRangeAutoLower(20, FIRSTVALS, RANGEEXT);

ifn.setNumBinsHint(5);  ifn.setRange(10, 20);
ian.setNumBinsHint(5);  ian.setRangeAuto(FIRSTVALS, RANGEEXT);
iaun.setNumBinsHint(5); iaun.setRangeAutoUpper(10, FIRSTVALS, RANGEEXT);
ialn.setNumBinsHint(5); ialn.setRangeAutoLower(20, FIRSTVALS, RANGEEXT);

df_.setRange(10, 20); df_.setMode(cHistogram::MODE_DOUBLES); // mode is not auto-selected, because transform happens immediately (FIXME is that good?)
da.setRangeAuto(FIRSTVALS, RANGEEXT);
dau.setRangeAutoUpper(10, FIRSTVALS, RANGEEXT);
dal.setRangeAutoLower(20, FIRSTVALS, RANGEEXT);

dfn.setNumBinsHint(5);  dfn.setRange(10, 20);
dan.setNumBinsHint(5);  dan.setRangeAuto(FIRSTVALS, RANGEEXT);
daun.setNumBinsHint(5); daun.setRangeAutoUpper(10, FIRSTVALS, RANGEEXT);
daln.setNumBinsHint(5); daln.setRangeAutoLower(20, FIRSTVALS, RANGEEXT);

cDensityEstBase *h[] = {
  &if_, &ia, &iau, &ial,
  &ifn, &ian, &iaun, &ialn,
  &iva,
  &df_, &da, &dau, &dal,
  &dfn, &dan, &daun, &daln,
  &dva,
  &ksa, &psq,
};
int nh = sizeof(h)/sizeof(cDensityEstBase*);
int nih = 9;  // first 9 histograms collect integers, the rest collect doubles

for (int i=0; i<FIRSTVALS+10; i++)
{
    if (i==0 || i==1 || i==FIRSTVALS-1 || i==FIRSTVALS+5) {
        // print range
        EV << i << " observations:\n";
        for (int k=0; k<nh; k++) {
            EV << " h[" << k << "] " << std::setw(k<10?23:22) << h[k]->getName() << ": ";
            if (!h[k]->binsAlreadySetUp())
                EV << "collecting\n";
            else {
                int nc = h[k]->getNumBins();
                EV << std::setw(2) << nc << " cells, " << h[k]->getBinEdge(0) << ".." << h[k]->getBinEdge(nc) << "\n";
            }
        }
        EV << "\n";
    }

    // test str()
    for (int k=0; k<nh; k++)
        h[k]->str();

    // collect values
    int intvalue = 5 + (i%20);              // range: 5..25
    double doublevalue = 15 + (i%20)/10.0;  // range: 15..16.9
    //EV << i << " --> " << intvalue << ", " << doublevalue << "\n";
    for (int k=0; k<nih; k++)
        h[k]->collect(intvalue);
    for (int k=nih; k<nh; k++)
        h[k]->collect(doublevalue);
}

#if defined(__clang__) || defined(__GNUC__)
#pragma GCC diagnostic pop
#endif

%subst: /-1\.7[0-9]+e\+308/DBL_MIN/

%contains: stdout
0 observations:
 h[0]               int-fixed: collecting
 h[1]                int-auto: collecting
 h[2]           int-autoupper: collecting
 h[3]           int-autolower: collecting
 h[4]         int-fixed-5cell: collecting
 h[5]          int-auto-5cell: collecting
 h[6]     int-autoupper-5cell: collecting
 h[7]     int-autolower-5cell: collecting
 h[8]        int-varhist-auto: collecting
 h[9]            double-fixed: collecting
 h[10]            double-auto: collecting
 h[11]       double-autoupper: collecting
 h[12]       double-autolower: collecting
 h[13]     double-fixed-5cell: collecting
 h[14]      double-auto-5cell: collecting
 h[15] double-autoupper-5cell: collecting
 h[16] double-autolower-5cell: collecting
 h[17]    double-varhist-auto: collecting
 h[18]     double-ksplit-auto: collecting
 h[19]         double-psquare:  0 cells, DBL_MIN..DBL_MIN

1 observations:
 h[0]               int-fixed: 10 cells, 10..20
 h[1]                int-auto: collecting
 h[2]           int-autoupper: collecting
 h[3]           int-autolower: collecting
 h[4]         int-fixed-5cell: collecting
 h[5]          int-auto-5cell: collecting
 h[6]     int-autoupper-5cell: collecting
 h[7]     int-autolower-5cell: collecting
 h[8]        int-varhist-auto: collecting
 h[9]            double-fixed: 50 cells, 10..20
 h[10]            double-auto: collecting
 h[11]       double-autoupper: collecting
 h[12]       double-autolower: collecting
 h[13]     double-fixed-5cell: collecting
 h[14]      double-auto-5cell: collecting
 h[15] double-autoupper-5cell: collecting
 h[16] double-autolower-5cell: collecting
 h[17]    double-varhist-auto: collecting
 h[18]     double-ksplit-auto: collecting
 h[19]         double-psquare:  0 cells, 15..15

99 observations:
 h[0]               int-fixed: 10 cells, 10..20
 h[1]                int-auto: 29 cells, 0..29
 h[2]           int-autoupper: 19 cells, 10..29
 h[3]           int-autolower: 20 cells, 0..20
 h[4]         int-fixed-5cell:  5 cells, 10..20
 h[5]          int-auto-5cell:  5 cells, 3..28
 h[6]     int-autoupper-5cell:  5 cells, 10..35
 h[7]     int-autolower-5cell:  5 cells, -5..20
 h[8]        int-varhist-auto: collecting
 h[9]            double-fixed: 50 cells, 10..20
 h[10]            double-auto: 59 cells, 14.475..17.425
 h[11]       double-autoupper: 75 cells, 10..17.5
 h[12]       double-autolower: 55 cells, 14.5..20
 h[13]     double-fixed-5cell:  5 cells, 10..20
 h[14]      double-auto-5cell:  5 cells, 14.75..17.25
 h[15] double-autoupper-5cell:  7 cells, 10..17
 h[16] double-autolower-5cell:  5 cells, 15..20
 h[17]    double-varhist-auto: collecting
 h[18]     double-ksplit-auto: collecting
 h[19]         double-psquare: 10 cells, 15..16.9

105 observations:
 h[0]               int-fixed: 10 cells, 10..20
 h[1]                int-auto: 29 cells, 0..29
 h[2]           int-autoupper: 19 cells, 10..29
 h[3]           int-autolower: 20 cells, 0..20
 h[4]         int-fixed-5cell:  5 cells, 10..20
 h[5]          int-auto-5cell:  5 cells, 3..28
 h[6]     int-autoupper-5cell:  5 cells, 10..35
 h[7]     int-autolower-5cell:  5 cells, -5..20
 h[8]        int-varhist-auto: 11 cells, 5..24
 h[9]            double-fixed: 50 cells, 10..20
 h[10]            double-auto: 59 cells, 14.475..17.425
 h[11]       double-autoupper: 75 cells, 10..17.5
 h[12]       double-autolower: 55 cells, 14.5..20
 h[13]     double-fixed-5cell:  5 cells, 10..20
 h[14]      double-auto-5cell:  5 cells, 14.75..17.25
 h[15] double-autoupper-5cell:  7 cells, 10..17
 h[16] double-autolower-5cell:  5 cells, 15..20
 h[17]    double-varhist-auto: 11 cells, 15..16.9
 h[18]     double-ksplit-auto:  6 cells, 14.05..17.85
 h[19]         double-psquare: 10 cells, 15..16.9