Skip to content

Commit 43a1a8a

Browse files
committed
Add target() example to docs
1 parent b36c896 commit 43a1a8a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

hypothesis-python/docs/details.rst

+13
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,19 @@ there is a natural metric like "floating-point error", "load factor" or
420420

421421
.. autofunction:: hypothesis.target
422422

423+
.. code-block:: python
424+
425+
from hypothesis import given, strategies as st, target
426+
427+
428+
@given(st.floats(0, 1e100), st.floats(0, 1e100), st.floats(0, 1e100))
429+
def test_associativity_with_target(a, b, c):
430+
ab_c = (a + b) + c
431+
a_bc = a + (b + c)
432+
difference = abs(ab_c - a_bc)
433+
target(difference) # Without this, the test almost always passes
434+
assert difference < 2.0
435+
423436
We recommend that users also skim the papers introducing targeted PBT;
424437
from `ISSTA 2017 <http://proper.softlab.ntua.gr/papers/issta2017.pdf>`__
425438
and `ICST 2018 <http://proper.softlab.ntua.gr/papers/icst2018.pdf>`__.

0 commit comments

Comments
 (0)