Skip to content

Commit 69d30aa

Browse files
cyrrazandrzejnovak
authored andcommitted
test: add test of binwnorm()
1 parent b4818cb commit 69d30aa

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/test_enhanced_plottable_histogram.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ def test_fixed_errors(basic_hist):
304304

305305

306306
def test_binwnorm_idempotence(basic_hist):
307+
# The basic histogram has unitary bin widths,
308+
# so binwnorm should not change the values.
307309
h = basic_hist
308310
before = h.values().copy()
309311
h1 = h.binwnorm()
@@ -313,6 +315,26 @@ def test_binwnorm_idempotence(basic_hist):
313315
assert np.allclose(h2.values(), before)
314316

315317

318+
def test_binwnorm_non_unitary_bin_widths():
319+
edges = np.array([[0, 1], [1, 3]], dtype=float)
320+
values = np.array([1.0, 4.0], dtype=float)
321+
variances = values
322+
h = EnhancedPlottableHistogram(
323+
values, edges=edges, variances=variances, w2method="sqrt"
324+
)
325+
# The first bin is normalized by 1, the second by 2.
326+
h.binwnorm()
327+
assert np.allclose(h.values(), [1.0, 2.0])
328+
assert np.allclose([h.yerr_lo], [1.0, 1.0])
329+
assert np.allclose([h.yerr_hi], [1.0, 1.0])
330+
331+
# Another normalization should not change the values
332+
h.binwnorm()
333+
assert np.allclose(h.values(), [1.0, 2.0])
334+
assert np.allclose([h.yerr_lo], [1.0, 1.0])
335+
assert np.allclose([h.yerr_hi], [1.0, 1.0])
336+
337+
316338
def test_density_normalization(basic_hist):
317339
h = basic_hist
318340
h1 = h.density()

0 commit comments

Comments
 (0)