Skip to content

Commit

Permalink
speed up test_shrinks_downwards_to_integers
Browse files Browse the repository at this point in the history
  • Loading branch information
tybug committed Dec 27, 2024
1 parent 75d1f42 commit a4c8648
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions hypothesis-python/tests/quality/test_float_shrinking.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@

import pytest

from hypothesis import (
HealthCheck,
Verbosity,
example,
given,
settings,
strategies as st,
)
from hypothesis import example, given, strategies as st
from hypothesis.internal.compat import ceil

from tests.common.debug import minimal
Expand All @@ -39,21 +32,16 @@ def test_can_shrink_in_variable_sized_context(n):
@example(1.7976931348623157e308)
@example(1.5)
@given(st.floats(min_value=0, allow_infinity=False, allow_nan=False))
@settings(deadline=None, suppress_health_check=list(HealthCheck))
def test_shrinks_downwards_to_integers(f):
g = minimal(
st.floats().filter(lambda x: x >= f),
settings=settings(verbosity=Verbosity.quiet, max_examples=10**6),
)
assert g == ceil(f)
assert minimal(st.floats(min_value=f)) == ceil(f)


@example(1)
@given(st.integers(1, 2**16 - 1))
@settings(deadline=None, suppress_health_check=list(HealthCheck), max_examples=10)
def test_shrinks_downwards_to_integers_when_fractional(b):
g = minimal(
st.floats().filter(lambda x: b < x < 2**53 and int(x) != x),
settings=settings(verbosity=Verbosity.quiet, max_examples=10**6),
st.floats(
min_value=b, max_value=2**53, exclude_min=True, exclude_max=True
).filter(lambda x: int(x) != x)
)
assert g == b + 0.5

0 comments on commit a4c8648

Please sign in to comment.