示例#1
0
def test_add():
    assert list(Sorted([0, 1, 2]) + Sorted([3, 4])) == [0, 1, 2, 3, 4]
示例#2
0
def test_one_argument():
    s = Sorted([1, 2, 3])
    assert merge(s) == s
示例#3
0
def test_direction_mismatch():
    with pytest.raises(DirectionMismatchError):
        merge(Sorted([1, 2, 3]), Sorted([5, 4, 3], reverse=True))
示例#4
0
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)
示例#6
0
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]
示例#7
0
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) == []
示例#9
0
def test_empty():
    assert Sorted([]) == Sorted([])
示例#10
0
def test_wrong_direction():
    assert Sorted([]) != Sorted([], reverse=True)
示例#11
0
def test_all_set():
    iterable = itertools.count()
    assert Sorted(iterable) == Sorted(iterable)
示例#12
0
def test_wrong_iterable():
    assert Sorted(range(100)) != Sorted(itertools.count())
示例#13
0
def test_wrong_key():
    assert Sorted([]) != Sorted([], key=abs)
示例#14
0
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')
示例#15
0
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')