| 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.internal.conjecture.shrinking.common import find_integer |
| 12 |
|
| 13 |
FIND_INTEGER_COSTS = {} |
| 14 |
|
| 15 |
|
| 16 |
def find_integer_cost(n): |
| 17 |
try: |
| 18 |
return FIND_INTEGER_COSTS[n] |
| 19 |
except KeyError: |
| 20 |
pass |
| 21 |
|
| 22 |
cost = 0 |
| 23 |
|
| 24 |
def test(i): |
| 25 |
nonlocal cost |
| 26 |
cost += 1 |
| 27 |
return i <= n |
| 28 |
|
| 29 |
find_integer(test) |
| 30 |
|
| 31 |
return FIND_INTEGER_COSTS.setdefault(n, cost) |