Debian Codegraph @

hypothesis-python/tests/numpy/test_fill_values.py

raw
1 # This file is part of Hypothesis, which may be found at
2 # https://github.com/HypothesisWorks/hypothesis/
3 #
4 # Copyright the Hypothesis Authors.
5 # Individual contributors are listed in AUTHORS.rst and the git log.
6 #
7 # This Source Code Form is subject to the terms of the Mozilla Public License,
8 # v. 2.0. If a copy of the MPL was not distributed with this file, You can
9 # obtain one at https://mozilla.org/MPL/2.0/.
10
11 from hypothesis import given, strategies as st
12 from hypothesis.extra.numpy import arrays
13
14 from tests.common.debug import find_any, minimal
15
16
17 @given(arrays(object, 100, elements=st.builds(list)))
18 def test_generated_lists_are_distinct(ls):
19 assert len(set(map(id, ls))) == len(ls)
20
21
22 @st.composite
23 def distinct_integers(draw):
24 used = draw(st.shared(st.builds(set), key="distinct_integers.used"))
25 i = draw(st.integers(0, 2**64 - 1).filter(lambda x: x not in used))
26 used.add(i)
27 return i
28
29
30 @given(arrays("uint64", 10, elements=distinct_integers()))
31 def test_does_not_reuse_distinct_integers(arr):
32 assert len(set(arr)) == len(arr)
33
34
35 def test_may_reuse_distinct_integers_if_asked():
36 find_any(
37 arrays("uint64", 10, elements=distinct_integers(), fill=distinct_integers()),
38 lambda x: len(set(x)) < len(x),
39 )
40
41
42 def test_minimizes_to_fill():
43 result = minimal(arrays(float, 10, fill=st.just(3.0)))
44 assert (result == 3.0).all()
45
46
47 @given(
48 arrays(
49 dtype=float,
50 elements=st.floats(allow_nan=False).filter(bool),
51 shape=(3, 3, 3),
52 fill=st.just(1.0),
53 )
54 )
55 def test_fills_everything(x):
56 assert x.all()