diff --git a/tests/test_Histogram.py b/tests/test_Histogram.py index ce8e528a..efc3640b 100644 --- a/tests/test_Histogram.py +++ b/tests/test_Histogram.py @@ -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