예제 #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)
예제 #2
0
파일: test_seqs.py 프로젝트: sjl421/funcy
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'
예제 #3
0
파일: test_seqs.py 프로젝트: sjl421/funcy
def test_with_next():
    assert list(with_next(range(3))) == [(0, 1), (1, 2), (2, None)]
예제 #4
0
파일: test_seqs.py 프로젝트: sjl421/funcy
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]]
예제 #5
0
파일: test_seqs.py 프로젝트: sjl421/funcy
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}
예제 #6
0
파일: test_seqs.py 프로젝트: sjl421/funcy
def test_split_at():
    assert lsplit_at(2, range(5)) == ([0, 1], [2, 3, 4])
예제 #7
0
파일: test_seqs.py 프로젝트: sjl421/funcy
def test_split():
    assert lmap(list, split(_ % 2, range(5))) == [[1, 3], [0, 2, 4]]
예제 #8
0
파일: test_seqs.py 프로젝트: sjl421/funcy
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]
예제 #9
0
파일: test_seqs.py 프로젝트: Suor/funcy
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]]
예제 #10
0
파일: test_seqs.py 프로젝트: Suor/funcy
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}
예제 #11
0
파일: test_seqs.py 프로젝트: Suor/funcy
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']}
예제 #12
0
파일: test_seqs.py 프로젝트: Suor/funcy
def test_split_at():
    assert lsplit_at(2, range(5)) == ([0, 1], [2, 3, 4])
예제 #13
0
파일: test_seqs.py 프로젝트: Suor/funcy
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))
예제 #14
0
파일: test_seqs.py 프로젝트: Suor/funcy
def test_split():
    assert lmap(list, split(_ % 2, range(5))) == [[1, 3], [0, 2, 4]]
예제 #15
0
파일: test_seqs.py 프로젝트: Suor/funcy
def test_cat():
    assert lcat('abcd') == list('abcd')
    assert lcat(range(x) for x in range(3)) == [0, 0, 1]
예제 #16
0
파일: test_seqs.py 프로젝트: Suor/funcy
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]]
예제 #17
0
파일: test_seqs.py 프로젝트: sjl421/funcy
def test_remove():
    assert lremove(_ > 3, range(10)) == [0, 1, 2, 3]
    assert lremove('^a', ['a', 'b', 'ba']) == ['b', 'ba']
예제 #18
0
파일: test_seqs.py 프로젝트: Suor/funcy
def test_with_prev():
    assert list(with_prev(range(3))) == [(0, None), (1, 0), (2, 1)]
예제 #19
0
파일: test_seqs.py 프로젝트: sjl421/funcy
def test_cat():
    assert lcat('abcd') == list('abcd')
    assert lcat(range(x) for x in range(3)) == [0, 0, 1]
예제 #20
0
파일: test_seqs.py 프로젝트: Suor/funcy
def test_with_next():
    assert list(with_next(range(3))) == [(0, 1), (1, 2), (2, None)]
예제 #21
0
파일: test_seqs.py 프로젝트: sjl421/funcy
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))
예제 #22
0
파일: test_seqs.py 프로젝트: Suor/funcy
def test_pairwise():
    assert list(pairwise(range(3))) == [(0, 1), (1, 2)]
예제 #23
0
파일: test_seqs.py 프로젝트: sjl421/funcy
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']
    }
예제 #24
0
파일: test_seqs.py 프로젝트: Suor/funcy
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'
예제 #25
0
파일: test_seqs.py 프로젝트: sjl421/funcy
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]]
예제 #26
0
파일: test_seqs.py 프로젝트: Suor/funcy
def test_ilen():
    assert ilen('xyz') == 3
    assert ilen(range(10)) == 10
예제 #27
0
파일: test_seqs.py 프로젝트: sjl421/funcy
def test_with_prev():
    assert list(with_prev(range(3))) == [(0, None), (1, 0), (2, 1)]
예제 #28
0
파일: test_seqs.py 프로젝트: Suor/funcy
def test_remove():
    assert lremove(_ > 3, range(10)) == [0, 1, 2, 3]
    assert lremove('^a', ['a', 'b', 'ba']) == ['b', 'ba']
예제 #29
0
파일: test_seqs.py 프로젝트: sjl421/funcy
def test_pairwise():
    assert list(pairwise(range(3))) == [(0, 1), (1, 2)]
예제 #30
0
파일: test_seqs.py 프로젝트: Suor/funcy
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]
예제 #31
0
파일: test_seqs.py 프로젝트: sjl421/funcy
def test_ilen():
    assert ilen('xyz') == 3
    assert ilen(range(10)) == 10
예제 #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))