pydu/tests/test_iter.py

26 lines
509 B
Python
Raw Normal View History

2018-02-02 16:02:49 +00:00
import pytest
2018-02-02 16:23:09 +00:00
from pydu.iter import first, last, all, any
2018-02-02 16:02:49 +00:00
@pytest.mark.parametrize(
'iterable', (
[1, 2],
(1, 2),
{1, 2},
{1: 1, 2: 2},
iter([1, 2])
))
def test_first_last(iterable):
assert first(iterable) == 1
assert last(iterable) == 2
2018-02-02 16:23:09 +00:00
def test_all():
assert all([0, 1, 2], lambda x: x+1)
assert not all([0, 1, 2], lambda x: x)
def test_any():
assert any([-1, -1, 0], lambda x: x+1)
assert not any([-1, -1, -1], lambda x: x + 1)