Skip to content
Snippets Groups Projects
Commit d51eb5f6 authored by Axel Naumann's avatar Axel Naumann
Browse files

Increase coverage.

parent abe4ec8d
No related branches found
No related tags found
No related merge requests found
......@@ -63,6 +63,7 @@ TEST(AxisTest, NumBins) {
// Through concrete axis incarnations (and to TAxisConfig)
{
TAxisEquidistant ax("TITLE", 10, -1., 1.);
EXPECT_EQ(10 + nOverflow, ax.GetNBins());
EXPECT_EQ(10, ax.GetNBinsNoOver());
EXPECT_EQ(0, ax.GetUnderflowBin());
......@@ -72,6 +73,34 @@ TEST(AxisTest, NumBins) {
EXPECT_EQ(true, ax.IsOverflowBin(11));
EXPECT_EQ(true, ax.IsOverflowBin(16));
EXPECT_FLOAT_EQ(0.2, ax.GetBinWidth());
EXPECT_EQ(7, ax.FindBin(0.22));
EXPECT_EQ(0, ax.FindBin(-2.));
EXPECT_EQ(10, ax.FindBin(0.99));
EXPECT_EQ(11, ax.FindBin(1.01));
EXPECT_EQ(11, ax.FindBin(101.));
EXPECT_FLOAT_EQ(0.7, ax.GetBinCenter(9));
EXPECT_FLOAT_EQ(0.6, ax.GetBinFrom(9));
EXPECT_FLOAT_EQ(0.8, ax.GetBinTo(9));
EXPECT_LT(ax.GetBinCenter(0), -1.);
EXPECT_LT(ax.GetBinFrom(0), -1.);
EXPECT_FLOAT_EQ(-1., ax.GetBinTo(0));
EXPECT_LT(ax.GetBinCenter(-1), -1.);
EXPECT_LT(ax.GetBinFrom(-2), -1.);
EXPECT_LE(ax.GetBinTo(-3), -1.);
EXPECT_LT(1., ax.GetBinCenter(11));
EXPECT_FLOAT_EQ(1., ax.GetBinFrom(11));
EXPECT_LT(1., ax.GetBinTo(11));
EXPECT_LT(1., ax.GetBinCenter(111));
EXPECT_LE(1., ax.GetBinFrom(111));
EXPECT_LT(1., ax.GetBinTo(111));
TAxisConfig axcfg(ax);
EXPECT_EQ(ax.GetNBins(), axcfg.GetNBins());
EXPECT_EQ(10, axcfg.GetNBinsNoOver());
......
#include "gtest/gtest.h"
#include <ROOT/THist.h>
#include <ROOT/THistBinIter.h>
#include <cmath>
using namespace ROOT::Experimental;
// Tests the number of bins
TEST(BinIterNBins, NumBins) {
TH2F h({10, -1., 1.}, {10, -1., 1.});
EXPECT_EQ(12*12, h.GetImpl()->GetNBins());
double x = 0.11;
double y = 0.33;
double w = 3.141;
h.Fill({{x, y}}, w);
h.Fill({{x, y}}, 2. * w);
EXPECT_FLOAT_EQ(3. * w, h.GetBinContent({{x,y}}));
int xbin = h.GetImpl()->GetAxis(0).FindBin(x);
EXPECT_EQ(6, xbin);
int ybin = h.GetImpl()->GetAxis(1).FindBin(y);
EXPECT_EQ(7, ybin);
int linbin = h.GetImpl()->GetBinIndex({{x, y}});
const int expectedLinBin = xbin + ybin * 12;
EXPECT_EQ(expectedLinBin, linbin);
EXPECT_FLOAT_EQ(3. * w, h.GetImpl()->GetBinContent(linbin));
int foundbin = -1;
double foundweight = -1.;
double founduncert = -1.;
std::array<double,2> foundcoord{};
int nBins = 0;
for (auto &&bin: h) {
(void)bin;
auto binCenter = bin.GetCenter();
if (std::fabs(binCenter[0] - x) < 0.1 && std::fabs(binCenter[1] - y) < 0.1) {
foundbin = nBins;
foundcoord = binCenter;
foundweight = bin.GetContent();
founduncert = bin.GetUncertainty();
}
++nBins;
}
EXPECT_EQ(h.GetImpl()->GetNBins(), nBins);
EXPECT_FLOAT_EQ(0.1, foundcoord[0]);
EXPECT_FLOAT_EQ(0.3, foundcoord[1]);
EXPECT_EQ(expectedLinBin, foundbin);
EXPECT_FLOAT_EQ(3. * w, foundweight);
EXPECT_FLOAT_EQ(std::sqrt(w * w + (2 * w) * (2 * w)), founduncert);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment