diff --git a/hist/hist/src/TAxis.cxx b/hist/hist/src/TAxis.cxx index 641c09edb602c..49ea43db92a0b 100644 --- a/hist/hist/src/TAxis.cxx +++ b/hist/hist/src/TAxis.cxx @@ -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]; @@ -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]; diff --git a/hist/hist/test/test_TH1.cxx b/hist/hist/test/test_TH1.cxx index 471e8068e4718..73d4ba9f5cef1 100644 --- a/hist/hist/test/test_TH1.cxx +++ b/hist/hist/test/test_TH1.cxx @@ -11,6 +11,8 @@ #include #include +#include "ROOT/TestSupport.hxx" + // StatOverflows TH1 TEST(TH1, StatOverflows) { @@ -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"); +} diff --git a/test/stressHistogram.cxx b/test/stressHistogram.cxx index 09b3e64750c6a..bfb7361a83806 100644 --- a/test/stressHistogram.cxx +++ b/test/stressHistogram.cxx @@ -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; + } }