# This test code was written by the `hypothesis.extra.ghostwriter` module
# and is provided under the Creative Commons Zero public domain dedication.

import pytest
from hypothesis import given, reject, strategies as st, target


@given(
    iterable=st.one_of(st.iterables(st.integers()), st.iterables(st.text())),
    key=st.none(),
    reverse=st.booleans(),
)
def test_equivalent_sorted_sorted(iterable, key, reverse):
    try:
        result_0_sorted = sorted(iterable, key=key, reverse=reverse)
        exc_type = None
        target(1, label="input was valid")
    except ValueError:
        reject()
    except Exception as exc:
        exc_type = type(exc)

    if exc_type:
        with pytest.raises(exc_type):
            sorted(iterable, key=key, reverse=reverse)
    else:
        result_1_sorted = sorted(iterable, key=key, reverse=reverse)
        assert result_0_sorted == result_1_sorted, (result_0_sorted, result_1_sorted)
