mirror of
https://github.com/correl/typesafe-monads.git
synced 2024-11-21 19:18:42 +00:00
Functor tests
This commit is contained in:
parent
0348e8d82b
commit
7ce173e829
1 changed files with 24 additions and 0 deletions
24
tests/test_functors.py
Normal file
24
tests/test_functors.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
import pytest # type: ignore
|
||||
from typing import Callable, Type, TypeVar
|
||||
from monads import Functor, Maybe, Result
|
||||
|
||||
T = TypeVar("T")
|
||||
S = TypeVar("S")
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", params=[Maybe, Result])
|
||||
def monad(request) -> Type:
|
||||
return request.param
|
||||
|
||||
|
||||
def test_identity(monad) -> None:
|
||||
m: Functor = monad.pure(3)
|
||||
identity: Callable[[T], T] = lambda x: x
|
||||
assert m == m.map(identity)
|
||||
|
||||
|
||||
def test_associativity(monad) -> None:
|
||||
f: Callable[[int], int] = lambda x: x + 1
|
||||
g: Callable[[int], str] = lambda x: str(x)
|
||||
m: Functor = monad.pure(3)
|
||||
assert m.map(lambda x: g(f(x))) == m.map(f).map(g)
|
Loading…
Reference in a new issue