~homeworkprod/byceps

ref: 9f63b62a2b4647a97ebd3b6356d937ffa1d88876 byceps/tests/util/test_iterables.py -rw-r--r-- 1.2 KiB
9f63b62a — Jochen Kupperschmidt Note that Python 3.6 is a supported Python version 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
:Copyright: 2006-2017 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from nose2.tools import params

from byceps.util.iterables import find, index_of, pairwise


@params(
    (
        lambda x: x > 3,
        [],
        None,
    ),
    (
        lambda x: x > 3,
        [-2, 0, 1, 3],
        None,
    ),
    (
        lambda x: x > 3,
        [2, 3, 4, 5],
        4,
    ),
)
def test_find(predicate, iterable, expected):
    actual = find(predicate, iterable)
    assert actual == expected


@params(
    (
        lambda x: x > 3,
        [],
        None,
    ),
    (
        lambda x: x > 1,
        [2, 3, 4, 5],
        0,
    ),
    (
        lambda x: x > 3,
        [2, 3, 4, 5],
        2,
    ),
    (
        lambda x: x > 6,
        [2, 3, 4, 5],
        None,
    ),
)
def test_index_of(predicate, iterable, expected):
    actual = index_of(predicate, iterable)
    assert actual == expected


@params(
    (
        [],
        [],
    ),
    (
        ['a', 'b', 'c'],
        [('a', 'b'), ('b', 'c')],
    ),
    (
        range(5),
        [(0, 1), (1, 2), (2, 3), (3, 4)],
    ),
)
def test_pairwise(iterable, expected):
    actual = pairwise(iterable)
    assert list(actual) == expected