def test_add(): assert list(Sorted([0, 1, 2]) + Sorted([3, 4])) == [0, 1, 2, 3, 4]
def test_one_argument(): s = Sorted([1, 2, 3]) assert merge(s) == s
def test_direction_mismatch(): with pytest.raises(DirectionMismatchError): merge(Sorted([1, 2, 3]), Sorted([5, 4, 3], reverse=True))
def test_key_function_mismatch(): with pytest.raises(KeyFunctionMismatchError): # noinspection PyTypeChecker merge(Sorted([1, 2, 3]), Sorted(['c', 'bb', 'aaa'], key=len))
def test_sub_reverse_mismatch(): with pytest.raises(DirectionMismatchError): Sorted(itertools.count()) - Sorted(itertools.count(), reverse=True)
def test_two_arguments(): even = Sorted([0, 2, 4]) odd = Sorted([1, 3, 5]) merged = merge(even, odd) assert list(merged) == [0, 1, 2, 3, 4, 5]
def test_unique(): s = Sorted([1, 2, 2, 3]) assert list(s.unique()) == [1, 2, 3]
def test_sub(): s1 = Sorted(range(10)) s2 = Sorted(itertools.count()) result = s1 - s2 assert list(result) == []
def test_empty(): assert Sorted([]) == Sorted([])
def test_wrong_direction(): assert Sorted([]) != Sorted([], reverse=True)
def test_all_set(): iterable = itertools.count() assert Sorted(iterable) == Sorted(iterable)
def test_wrong_iterable(): assert Sorted(range(100)) != Sorted(itertools.count())
def test_wrong_key(): assert Sorted([]) != Sorted([], key=abs)
def test_key_mismatch_error(): err = KeyFunctionMismatchError(Sorted([1, 2, 3]), Sorted(['a', 'b', 'c'], key=len)) assert str(err).startswith('Given 2 iterables are incompatible')
def test_reserve_mismatch_error(): err = DirectionMismatchError(Sorted([1, 2, 3]), Sorted(['c', 'b', 'a'], reverse=True), Sorted([4, 5, 6])) assert str(err).startswith('Given 3 iterables are incompatible')