Skip to content

Commit

Permalink
bugfix: sample_between failing on small ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserfarouk committed Dec 25, 2023
1 parent e18eb18 commit dddd1eb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions negmas/preferences/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def sample_between(
"""
if n == 0:
return []
if end - start < 1e-8:
return [start] * n
samples = np.linspace(start, end, num=n, endpoint=endpoint)
if len(samples) > 2:
samples[1:-1] += (
Expand Down
4 changes: 3 additions & 1 deletion tests/core/test_ufun_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ def test_distribute_integer_randomly_on_none(n, m):
n=st.integers(1, 100),
endpoint=st.booleans(),
main_range_min=st.floats(0.0, 0.5),
main_range_range=st.floats(0, 0.5),
main_range_range=st.floats(0.0, 0.5),
)
def test_sample_between(start, rng, n, endpoint, main_range_min, main_range_range):
main_range_min = round(main_range_min, 6)
main_range_range = round(main_range_range, 6)
end = start + rng
lst = sample_between(
start, end, n, endpoint, (main_range_min, main_range_min + main_range_range)
Expand Down

0 comments on commit dddd1eb

Please sign in to comment.