From b3a2456f2b2033f8eeee6f84ce69e757022918e3 Mon Sep 17 00:00:00 2001 From: rlbarker Date: Mon, 26 Feb 2024 22:15:50 +0000 Subject: [PATCH] Added checks that tolerance value is between 0 and 1 (#2884) --- openmc/stats/univariate.py | 3 +++ tests/unit_tests/test_stats.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/openmc/stats/univariate.py b/openmc/stats/univariate.py index b33f88af86..e7ff64257a 100644 --- a/openmc/stats/univariate.py +++ b/openmc/stats/univariate.py @@ -280,6 +280,9 @@ class Discrete(Univariate): Discrete distribution with low-importance points removed """ + cv.check_less_than("tolerance", tolerance, 1.0, equality=True) + cv.check_greater_than("tolerance", tolerance, 0.0, equality=True) + # Determine (reversed) sorted order of probabilities intensity = self.p * self.x index_sort = np.argsort(intensity)[::-1] diff --git a/tests/unit_tests/test_stats.py b/tests/unit_tests/test_stats.py index 8438535ff8..f5368e912f 100644 --- a/tests/unit_tests/test_stats.py +++ b/tests/unit_tests/test_stats.py @@ -89,6 +89,12 @@ def test_clip_discrete(): d_same = d.clip(1e-6, inplace=True) assert d_same is d + with pytest.raises(ValueError): + d.clip(-1.) + + with pytest.raises(ValueError): + d.clip(5) + def test_uniform(): a, b = 10.0, 20.0