Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
RenataKrupczak committed Oct 24, 2024
1 parent d00e94e commit 5b2c814
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions tests/test_Histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,29 @@ def test_add_value_single_number_to_multiple_histograms():
)

def test_add_value_out_of_range():
# Test adding values outside the histogram range
hist = Histogram((0, 10, 10))
histogram_original = hist.histograms_.copy()
values_out = [12.5, 10, -1]
# Test adding values inside and outside the histograms range
hist = Histogram((0, 20, 20))
valid_values = [1, 2, 10, 18]
for value in valid_values:
hist.add_value(value)

histogram_after_valid = hist.histograms_.copy()

outlier_values = [-1, 21, 40, 20]
with pytest.warns(UserWarning, match="Exceeding values are ignored"):
for value in values_out:
for value in outlier_values:
hist.add_value(value)
# Ensure that the histogram has not changed after trying to add out-of-range values
assert np.array_equal(hist.histograms_, histogram_original), "Histogram should not be modified with out-of-range values"

# Check that the histogram did not change after adding outliers
assert np.allclose(hist.histograms_, histogram_after_valid), "Histogram changed after adding out-of-range values."

hist2 = Histogram((0, 10, 10))
values = [1, 4, 6.6, 12, 22, -1]
with pytest.warns(UserWarning, match="Exceeding values are ignored"):
for value in values:
hist2.add_value(value)

assert np.allclose(hist2.histogram(), np.array([0, 1, 0, 0, 1, 0, 1, 0, 0, 0])), "Histogram changed after adding out-of-range values."

def test_remove_bin_out_of_range():
# Test removing a bin at an index out of range
Expand Down

0 comments on commit 5b2c814

Please sign in to comment.