<s> """<STR_LIT>""" <EOL> import unittest <EOL> from oslash . identity import Identity <EOL> from oslash . util import identity , compose , fmap <EOL> pure = Identity . pure <EOL> unit = Identity . unit <EOL> class TestIdentityFunctor ( unittest . TestCase ) : <EOL> def test_identity_functor_map ( self ) : <EOL> x = unit ( <NUM_LIT> ) <EOL> f = lambda x : x * <NUM_LIT:10> <EOL> self . assertEqual ( <EOL> x . map ( f ) , <EOL> unit ( <NUM_LIT> ) <EOL> ) <EOL> def test_identity_functor_law_1 ( self ) : <EOL> x = unit ( <NUM_LIT> ) <EOL> self . assertEqual ( <EOL> x . map ( identity ) , <EOL> x <EOL> ) <EOL> def test_identity_functor_law2 ( self ) : <EOL> def f ( x ) : <EOL> return x + <NUM_LIT:10> <EOL> def g ( x ) : <EOL> return x * <NUM_LIT:10> <EOL> x = unit ( <NUM_LIT> ) <EOL> self . assertEquals ( <EOL> x . map ( compose ( f , g ) ) , <EOL> x . map ( g ) . map ( f ) <EOL> ) <EOL> class TestIdentityApplicative ( unittest . TestCase ) : <EOL> def test_identity_applicative_law_functor ( self ) : <EOL> x = unit ( <NUM_LIT> ) <EOL> f = lambda x : x * <NUM_LIT> <EOL> self . assertEquals ( <EOL> pure ( f ) . apply ( x ) , <EOL> x . map ( f ) <EOL> ) <EOL> def test_identity_applicative_law_identity ( self ) : <EOL> v = unit ( <NUM_LIT> ) <EOL> self . assertEquals ( <EOL> pure ( identity ) . apply ( v ) , <EOL> v <EOL> ) <EOL> def test_identity_applicative_law_composition ( self ) : <EOL> w = unit ( <NUM_LIT> ) <EOL> u = pure ( lambda x : x * <NUM_LIT> ) <EOL> v = pure ( lambda x : x + <NUM_LIT> ) <EOL> self . assertEquals ( <EOL> pure ( fmap ) . apply ( u ) . apply ( v ) . apply ( w ) , <EOL> u . apply ( v . apply ( w ) ) <EOL> ) <EOL> def test_identity_applicative_law_homomorphism ( self ) : <EOL> x = <NUM_LIT> <EOL> f = lambda x : x * <NUM_LIT> <EOL> self . assertEquals ( <EOL> pure ( f ) . apply ( pure ( x ) ) , <EOL> pure ( f ( x ) ) <EOL> ) <EOL> def test_identity_applicative_law_interchange ( self ) : <EOL> y = <NUM_LIT> <EOL> u = unit ( lambda x : x * <NUM_LIT> ) <EOL> self . assertEquals ( <EOL> u . apply ( pure ( y ) ) , <EOL> pure ( lambda f : f ( y ) ) . apply ( u ) <EOL> ) <EOL> class TestIdentityMonad ( unittest . TestCase ) : <EOL> def test_identity_monad_bind ( self ) : <EOL> m = unit ( <NUM_LIT> ) <EOL> f = lambda x : unit ( x * <NUM_LIT:10> ) <EOL> self . assertEqual ( <EOL> m . bind ( f ) , <EOL> unit ( <NUM_LIT> ) <EOL> ) <EOL> def test_identity_monad_law_left_identity ( self ) : <EOL> f = lambda x : unit ( x + <NUM_LIT> ) <EOL> x = <NUM_LIT:3> <EOL> self . assertEqual ( <EOL> unit ( x ) . bind ( f ) , <EOL> f ( x ) <EOL> ) <EOL> def test_identity_monad_law_right_identity ( self ) : <EOL> m = unit ( "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> m . bind ( unit ) , <EOL> m <EOL> ) <EOL> def test_identity_monad_law_associativity ( self ) : <EOL> m = unit ( <NUM_LIT> ) <EOL> f = lambda x : unit ( x + <NUM_LIT:1000> ) <EOL> g = lambda y : unit ( y * <NUM_LIT> ) <EOL> self . assertEqual ( <EOL> m . bind ( f ) . bind ( g ) , <EOL> m . bind ( lambda x : f ( x ) . bind ( g ) ) <EOL> ) </s>
