Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hist/hist/src/TAxis.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ void TAxis::Set(Int_t nbins, const Float_t *xbins)
for (bin=0; bin<= fNbins; bin++)
fXbins.fArray[bin] = xbins[bin];
for (bin=1; bin<= fNbins; bin++)
if (fXbins.fArray[bin] < fXbins.fArray[bin-1])
if (fXbins.fArray[bin] <= fXbins.fArray[bin - 1])
Error("TAxis::Set", "bins must be in increasing order");
fXmin = fXbins.fArray[0];
fXmax = fXbins.fArray[fNbins];
Expand All @@ -818,7 +818,7 @@ void TAxis::Set(Int_t nbins, const Double_t *xbins)
for (bin=0; bin<= fNbins; bin++)
fXbins.fArray[bin] = xbins[bin];
for (bin=1; bin<= fNbins; bin++)
if (fXbins.fArray[bin] < fXbins.fArray[bin-1])
if (fXbins.fArray[bin] <= fXbins.fArray[bin - 1])
Error("TAxis::Set", "bins must be in increasing order");
fXmin = fXbins.fArray[0];
fXmax = fXbins.fArray[fNbins];
Expand Down
8 changes: 8 additions & 0 deletions hist/hist/test/test_TH1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <random>
#include <vector>

#include "ROOT/TestSupport.hxx"

// StatOverflows TH1
TEST(TH1, StatOverflows)
{
Expand Down Expand Up @@ -312,3 +314,9 @@ TEST(TH1, SetBufferedSumw2)
EXPECT_FLOAT_EQ(h1.GetBinContent(1), Entries * Weight);
EXPECT_FLOAT_EQ(h1.GetBinError(1), std::sqrt(Entries * Weight * Weight));
}

// https://github.com/root-project/root/issues/20185
TEST(TAxis, EqualBinEdges)
{
ROOT_EXPECT_ERROR(TAxis _({1, 1}), "TAxis::Set", "bins must be in increasing order");
}
6 changes: 5 additions & 1 deletion test/stressHistogram.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9185,13 +9185,17 @@ bool testArrayRebin()
h1->Fill( r.Uniform( minRange * .9 , maxRange * 1.1 ) );

// Create vector - generate bin edges ( nbins is always > 2)
// ignore fact that array may contains bins with zero size
Double_t * rebinArray = new Double_t[rebin];
r.RndmArray(rebin, rebinArray);
std::sort(rebinArray, rebinArray + rebin);
for ( Int_t i = 0; i < rebin; ++i ) {
rebinArray[i] = TMath::Nint( rebinArray[i] * ( h1->GetNbinsX() - 2 ) + 2 );
rebinArray[i] = h1->GetBinLowEdge( (Int_t) rebinArray[i] );
// compensate for the fact that array may contain bins with zero size
if (i > 0) {
if (rebinArray[i] <= rebinArray[i - 1])
rebinArray[i] = rebinArray[i - 1] + 1e-15;
}
}


Expand Down
Loading