| 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 |
| 12 |
from hypothesis.errors import InvalidArgument |
| 13 |
from hypothesis.strategies import permutations |
| 14 |
|
| 15 |
from tests.common.debug import check_can_generate_examples, minimal |
| 16 |
from tests.common.utils import fails_with |
| 17 |
|
| 18 |
|
| 19 |
def test_can_find_non_trivial_permutation(): |
| 20 |
x = minimal(permutations(list(range(5))), lambda x: x[0] != 0) |
| 21 |
|
| 22 |
assert x == [1, 0, 2, 3, 4] |
| 23 |
|
| 24 |
|
| 25 |
@given(permutations(list("abcd"))) |
| 26 |
def test_permutation_values_are_permutations(perm): |
| 27 |
assert len(perm) == 4 |
| 28 |
assert set(perm) == set("abcd") |
| 29 |
|
| 30 |
|
| 31 |
@given(permutations([])) |
| 32 |
def test_empty_permutations_are_empty(xs): |
| 33 |
assert xs == [] |
| 34 |
|
| 35 |
|
| 36 |
@fails_with(InvalidArgument) |
| 37 |
def test_cannot_permute_non_sequence_types(): |
| 38 |
check_can_generate_examples(permutations(set())) |