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

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


class TestEquivalentSortedSorted(unittest.TestCase):

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

        if exc_type:
            with self.assertRaises(exc_type):
                sorted(iterable, key=key, reverse=reverse)
        else:
            result_1_sorted = sorted(iterable, key=key, reverse=reverse)
            self.assertEqual(result_0_sorted, result_1_sorted)
