-
Notifications
You must be signed in to change notification settings - Fork 2
/
filterfalse.py
60 lines (39 loc) · 1.75 KB
/
filterfalse.py
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
class filterfalse:
def __init__(self, predicate, iterable):
raise NotImplementedError()
def test_filterfalse_is_iterator():
"""Verify that `filterfalse` is (or, at least, looks like) an iterator."""
assert hasattr(filterfalse, "__next__")
assert hasattr(filterfalse, "__iter__")
ff = filterfalse(bool, [])
assert iter(ff) is ff
def test_filterfalse_is_class():
"""Verify that `filterfalse` was defined as a class."""
assert isinstance(
filterfalse, type
) # Check that `filterfalse` is defined as a class...
assert filterfalse.__name__ == "filterfalse" # ... with the correct name.
def test_filterfalse():
"""Simple test for `filterfalse`."""
def is_big(number):
return number > 1000
numbers = [1, 2, 3, 999_999, 723_523_453_245]
assert list(filterfalse(is_big, numbers)) == [1, 2, 3]
def test_filterfalse_generator_iterator():
"""Test `filterfalse` with a generic iterator."""
def is_big(number):
return number > 1000
_numbers = [1, 2, 3, 999_999, 723_523_453_245]
numbers = (num for num in _numbers)
assert list(filterfalse(is_big, numbers)) == [1, 2, 3]
def test_filterfalse_empty_iterable():
"""Test `filterfalse` with an empty iterable."""
assert list(filterfalse(bool, [])) == []
def test_filterfalse_None_function():
"""Test `filterfalse` with `None` instead of a predicate function."""
assert list(filterfalse(None, [False, True, 0, 16, [], ()])) == [False, 0, [], ()]
def test_filterfalse_None_function_generator_iterator():
"""Test `filterfalse` with `None` and a generator iterator."""
_values = [False, True, 0, 16, [], ()]
values = (v for v in _values)
assert list(filterfalse(None, values)) == [False, 0, [], ()]