| 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 |
import pytest |
| 12 |
|
| 13 |
from hypothesis import Phase, settings |
| 14 |
from hypothesis.errors import Unsatisfiable |
| 15 |
from hypothesis.strategies import lists |
| 16 |
|
| 17 |
from tests.common import standard_types |
| 18 |
from tests.common.debug import minimal |
| 19 |
|
| 20 |
|
| 21 |
@pytest.mark.parametrize("spec", standard_types, ids=repr) |
| 22 |
def test_can_collectively_minimize(spec): |
| 23 |
n = 10 |
| 24 |
try: |
| 25 |
xs = minimal( |
| 26 |
lists(spec, min_size=n, max_size=n), |
| 27 |
lambda x: len(set(map(repr, x))) >= 2, |
| 28 |
settings(max_examples=2000, phases=(Phase.generate, Phase.shrink)), |
| 29 |
) |
| 30 |
assert len(xs) == n |
| 31 |
assert 2 <= len(set(map(repr, xs))) <= 3 |
| 32 |
except Unsatisfiable: |
| 33 |
pass |