-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_functor.py
More file actions
49 lines (25 loc) · 995 Bytes
/
test_functor.py
File metadata and controls
49 lines (25 loc) · 995 Bytes
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
"""Test synchronous functor."""
import typing as t
from typeclasses.functor import fmap
def times2(x): # pylint: disable=invalid-name
return x * 2
def test_fmap_str():
assert fmap(times2, 'test') == 'tteesstt'
def test_fmap_btes():
assert fmap(times2, bytes([1, 2, 3])) == bytes([2, 4, 6])
def test_fmap_dict():
assert fmap(times2, {'a': 1, 'b': 2}) == {'a': 2, 'b': 4}
def test_fmap_frozenset():
assert fmap(times2, frozenset({1, 2, 3})) == frozenset({2, 4, 6})
def test_fmap_list():
assert fmap(times2, [1, 2, 3]) == [2, 4, 6]
def test_fmap_range():
assert isinstance(fmap(times2, range(3)), t.Generator)
def test_fmap_set():
assert fmap(times2, {1, 2, 3}) == {2, 4, 6}
def test_fmap_tuple():
assert fmap(times2, (1, 2, 3)) == (2, 4, 6)
def test_dict_of_list():
assert fmap(times2, {'xs': [1, 2, 3]}) == {'xs': [2, 4, 6]}
def test_args_and_kwargs():
assert fmap(times2, ((1, 2), {'xs': [3, 4]})) == ((2, 4), {'xs': [6, 8]})