Debian Codegraph @

hypothesis-python/tests/conjecture/test_mutations.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 strategies as st
12
13 from tests.common.debug import find_any
14
15 tree = st.deferred(lambda: st.tuples(st.integers(), tree, tree)) | st.just(None)
16
17
18 def test_can_find_duplicated_subtree():
19 # look for an example of the form
20 #
21 # ┌─────┐
22 # ┌──────┤ a ├──────┐
23 # │ └─────┘ │
24 # ┌──┴──┐ ┌──┴──┐
25 # │ b │ │ a │
26 # └──┬──┘ └──┬──┘
27 # ┌────┴────┐ ┌────┴────┐
28 # ┌──┴──┐ ┌──┴──┐ ┌──┴──┐ ┌──┴──┐
29 # │ c │ │ d │ │ b │ │ ... │
30 # └─────┘ └─────┘ └──┬──┘ └─────┘
31 # ┌────┴────┐
32 # ┌──┴──┐ ┌──┴──┐
33 # │ c │ │ d │
34 # └─────┘ └─────┘
35 #
36 # If we just checked that (b, c, d) was duplicated somewhere, this could have
37 # happened as a result of normal mutation. Checking for the a parent node as
38 # well is unlikely to have been generated without tree mutation, however.
39 find_any(
40 tree,
41 (
42 lambda v: v is not None
43 and v[1] is not None
44 and v[2] is not None
45 and v[0] == v[2][0]
46 and v[1] == v[2][1]
47 ),
48 )