Example #1
0
def test_iterable():
    assert iterable([])
    assert iterable({})
    assert iterable('abc')
    assert iterable(iter([]))
    assert iterable(x for x in range(10))
    assert iterable(range(10))

    assert not iterable(1)
Example #2
0
def test_last():
    assert last('xyz') == 'z'
    assert last(range(1, 10)) == 9
    assert last([]) is None
    assert last(x for x in 'xyz') == 'z'
Example #3
0
def test_with_next():
    assert list(with_next(range(3))) == [(0, 1), (1, 2), (2, None)]
Example #4
0
def test_chunks():
    assert lchunks(2, [0, 1, 2, 3, 4]) == [[0, 1], [2, 3], [4]]
    assert lchunks(2, 1, [0, 1, 2, 3]) == [[0, 1], [1, 2], [2, 3], [3]]
    assert lchunks(3, 1, iter(range(3))) == [[0, 1, 2], [1, 2], [2]]
Example #5
0
def test_count_by():
    assert count_by(_ % 2, range(5)) == {0: 3, 1: 2}
    assert count_by(r'\d', ['a1', 'b2', 'c1']) == {'1': 2, '2': 1}
Example #6
0
def test_split_at():
    assert lsplit_at(2, range(5)) == ([0, 1], [2, 3, 4])
Example #7
0
def test_split():
    assert lmap(list, split(_ % 2, range(5))) == [[1, 3], [0, 2, 4]]
Example #8
0
def test_keep():
    assert lkeep(_ % 3, range(5)) == [1, 2, 1]
    assert lkeep(range(5)) == [1, 2, 3, 4]
    assert lkeep(mapcat(range, range(4))) == [1, 1, 2]
Example #9
0
def test_partition():
    assert lpartition(2, [0, 1, 2, 3, 4]) == [[0, 1], [2, 3]]
    assert lpartition(2, 1, [0, 1, 2, 3]) == [[0, 1], [1, 2], [2, 3]]
    # test iters
    assert lpartition(2, iter(range(5))) == [[0, 1], [2, 3]]
    assert lmap(list, lpartition(2, range(5))) == [[0, 1], [2, 3]]
Example #10
0
def test_count_by():
    assert count_by(_ % 2, range(5)) == {0: 3, 1: 2}
    assert count_by(r'\d', ['a1', 'b2', 'c1']) == {'1': 2, '2': 1}
Example #11
0
def test_group_by():
    assert group_by(_ % 2, range(5)) == {0: [0, 2, 4], 1: [1, 3]}
    assert group_by(r'\d', ['a1', 'b2', 'c1']) == {'1': ['a1', 'c1'], '2': ['b2']}
Example #12
0
def test_split_at():
    assert lsplit_at(2, range(5)) == ([0, 1], [2, 3, 4])
Example #13
0
def test_lsplit():
    assert lsplit(_ % 2, range(5)) == ([1, 3], [0, 2, 4])
    # This behaviour moved to split_at()
    with pytest.raises(TypeError): lsplit(2, range(5))
Example #14
0
def test_split():
    assert lmap(list, split(_ % 2, range(5))) == [[1, 3], [0, 2, 4]]
Example #15
0
def test_cat():
    assert lcat('abcd') == list('abcd')
    assert lcat(range(x) for x in range(3)) == [0, 0, 1]
Example #16
0
def test_chunks():
    assert lchunks(2, [0, 1, 2, 3, 4]) == [[0, 1], [2, 3], [4]]
    assert lchunks(2, 1, [0, 1, 2, 3]) == [[0, 1], [1, 2], [2, 3], [3]]
    assert lchunks(3, 1, iter(range(3))) == [[0, 1, 2], [1, 2], [2]]
Example #17
0
def test_remove():
    assert lremove(_ > 3, range(10)) == [0, 1, 2, 3]
    assert lremove('^a', ['a', 'b', 'ba']) == ['b', 'ba']
Example #18
0
def test_with_prev():
    assert list(with_prev(range(3))) == [(0, None), (1, 0), (2, 1)]
Example #19
0
def test_cat():
    assert lcat('abcd') == list('abcd')
    assert lcat(range(x) for x in range(3)) == [0, 0, 1]
Example #20
0
def test_with_next():
    assert list(with_next(range(3))) == [(0, 1), (1, 2), (2, None)]
Example #21
0
def test_lsplit():
    assert lsplit(_ % 2, range(5)) == ([1, 3], [0, 2, 4])
    # This behaviour moved to split_at()
    with pytest.raises(TypeError):
        lsplit(2, range(5))
Example #22
0
def test_pairwise():
    assert list(pairwise(range(3))) == [(0, 1), (1, 2)]
Example #23
0
def test_group_by():
    assert group_by(_ % 2, range(5)) == {0: [0, 2, 4], 1: [1, 3]}
    assert group_by(r'\d', ['a1', 'b2', 'c1']) == {
        '1': ['a1', 'c1'],
        '2': ['b2']
    }
Example #24
0
def test_last():
    assert last('xyz') == 'z'
    assert last(range(1, 10)) == 9
    assert last([]) is None
    assert last(x for x in 'xyz') == 'z'
Example #25
0
def test_partition():
    assert lpartition(2, [0, 1, 2, 3, 4]) == [[0, 1], [2, 3]]
    assert lpartition(2, 1, [0, 1, 2, 3]) == [[0, 1], [1, 2], [2, 3]]
    # test iters
    assert lpartition(2, iter(range(5))) == [[0, 1], [2, 3]]
    assert lmap(list, lpartition(2, range(5))) == [[0, 1], [2, 3]]
Example #26
0
def test_ilen():
    assert ilen('xyz') == 3
    assert ilen(range(10)) == 10
Example #27
0
def test_with_prev():
    assert list(with_prev(range(3))) == [(0, None), (1, 0), (2, 1)]
Example #28
0
def test_remove():
    assert lremove(_ > 3, range(10)) == [0, 1, 2, 3]
    assert lremove('^a', ['a', 'b', 'ba']) == ['b', 'ba']
Example #29
0
def test_pairwise():
    assert list(pairwise(range(3))) == [(0, 1), (1, 2)]
Example #30
0
def test_keep():
    assert lkeep(_ % 3, range(5)) == [1, 2, 1]
    assert lkeep(range(5)) == [1, 2, 3, 4]
    assert lkeep(mapcat(range, range(4))) == [1, 1, 2]
Example #31
0
def test_ilen():
    assert ilen('xyz') == 3
    assert ilen(range(10)) == 10
Example #32
0
def test_is_iter():
    assert is_iter(iter([]))
    assert is_iter(x for x in range(10))

    assert not is_iter([])
    assert not is_iter(range(10))