Skip to content

Commit

Permalink
Simplify test
Browse files Browse the repository at this point in the history
  • Loading branch information
jobh committed Feb 27, 2025
1 parent 8f0c7ea commit 296af5b
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions hypothesis-python/tests/conjecture/test_float_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
from hypothesis import HealthCheck, assume, example, given, settings, strategies as st
from hypothesis.internal.compat import ceil, extract_bits, floor
from hypothesis.internal.conjecture import floats as flt
from hypothesis.internal.conjecture.data import ConjectureData
from hypothesis.internal.conjecture.engine import ConjectureRunner
from hypothesis.internal.floats import float_to_int

from tests.conjecture.common import shrinking_from

EXPONENTS = list(range(flt.MAX_EXPONENT + 1))
assert len(EXPONENTS) == 2**11

Expand Down Expand Up @@ -208,16 +205,8 @@ def test_reject_out_of_bounds_floats_while_shrinking():


@pytest.mark.parametrize(
"nan",
[math.nan, -math.nan, struct.unpack('d', struct.pack('Q', 0xfff8000000000001))[0]]
"nan", [-math.nan, struct.unpack("d", struct.pack("Q", 0xFFF8000000000001))[0]]
)
def test_shrinks_to_canonical_nan(nan):
@shrinking_from([nan])
def shrinker(data: ConjectureData):
value = data.draw_float()
if math.isnan(value):
data.mark_interesting()

shrinker.shrink()
assert len(shrinker.choices) == 1
assert float_to_int(shrinker.choices[0]) == float_to_int(math.nan)
shrunk = minimal_from(nan, math.isnan)
assert float_to_int(shrunk) == float_to_int(math.nan)

0 comments on commit 296af5b

Please sign in to comment.