Skip to content

Commit 78366ca

Browse files
ferdymercuryvepadulano
authored andcommitted
[hist] disallow equal bin edges
Fixes #20185 credit goes to VanyaBelyaev
1 parent 733f4b0 commit 78366ca

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

hist/hist/src/TAxis.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ void TAxis::Set(Int_t nbins, const Float_t *xbins)
800800
for (bin=0; bin<= fNbins; bin++)
801801
fXbins.fArray[bin] = xbins[bin];
802802
for (bin=1; bin<= fNbins; bin++)
803-
if (fXbins.fArray[bin] < fXbins.fArray[bin-1])
803+
if (fXbins.fArray[bin] <= fXbins.fArray[bin - 1])
804804
Error("TAxis::Set", "bins must be in increasing order");
805805
fXmin = fXbins.fArray[0];
806806
fXmax = fXbins.fArray[fNbins];
@@ -818,7 +818,7 @@ void TAxis::Set(Int_t nbins, const Double_t *xbins)
818818
for (bin=0; bin<= fNbins; bin++)
819819
fXbins.fArray[bin] = xbins[bin];
820820
for (bin=1; bin<= fNbins; bin++)
821-
if (fXbins.fArray[bin] < fXbins.fArray[bin-1])
821+
if (fXbins.fArray[bin] <= fXbins.fArray[bin - 1])
822822
Error("TAxis::Set", "bins must be in increasing order");
823823
fXmin = fXbins.fArray[0];
824824
fXmax = fXbins.fArray[fNbins];

hist/hist/test/test_TH1.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <random>
1212
#include <vector>
1313

14+
#include "ROOT/TestSupport.hxx"
15+
1416
// StatOverflows TH1
1517
TEST(TH1, StatOverflows)
1618
{
@@ -312,3 +314,9 @@ TEST(TH1, SetBufferedSumw2)
312314
EXPECT_FLOAT_EQ(h1.GetBinContent(1), Entries * Weight);
313315
EXPECT_FLOAT_EQ(h1.GetBinError(1), std::sqrt(Entries * Weight * Weight));
314316
}
317+
318+
// https://github.com/root-project/root/issues/20185
319+
TEST(TAxis, EqualBinEdges)
320+
{
321+
ROOT_EXPECT_ERROR(TAxis _({1, 1}), "TAxis::Set", "bins must be in increasing order");
322+
}

0 commit comments

Comments
 (0)