Skip to content

Commit 544f52a

Browse files
committed
[Python][UHI] Add tests for the TH1 equality operator
1 parent 3e07a06 commit 544f52a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

bindings/pyroot/pythonizations/test/uhi_indexing.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,36 @@ def test_statistics_slice(self, hist_setup):
313313
assert hist_setup.GetStdDev() == pytest.approx(sliced_hist.GetStdDev(), rel=10e-5)
314314
assert hist_setup.GetMean() == pytest.approx(sliced_hist.GetMean(), rel=10e-5)
315315

316+
def test_equality_operator(self, hist_setup):
317+
if _special_setting(hist_setup) or isinstance(hist_setup, (ROOT.TH1C, ROOT.TH2C, ROOT.TH3C)):
318+
pytest.skip("This feature cannot be tested here")
319+
320+
assert hist_setup == hist_setup[...]
321+
322+
cloned_histograms = {
323+
"content": hist_setup.Clone(),
324+
"error": hist_setup.Clone(),
325+
"weight": hist_setup.Clone(),
326+
"axis": hist_setup.Clone(),
327+
}
328+
assert all(hist_setup == other for other in cloned_histograms.values())
329+
330+
# Change the content of a bin
331+
cloned_histograms["content"].SetBinContent(1, 100)
332+
assert hist_setup != cloned_histograms["content"]
333+
334+
# Change the error of a bin
335+
cloned_histograms["error"].SetBinError(1, 10)
336+
assert hist_setup != cloned_histograms["error"]
337+
338+
# Change the weight of a bin
339+
cloned_histograms["weight"].AddBinContent(1, 100)
340+
assert hist_setup != cloned_histograms["weight"]
341+
342+
# Change the x axis
343+
cloned_histograms["axis"].GetXaxis().Set(10, 1, 5)
344+
assert hist_setup != cloned_histograms["axis"]
345+
316346

317347
if __name__ == "__main__":
318348
pytest.main(args=[__file__])

0 commit comments

Comments
 (0)