<s> import unittest <EOL> from oslash import Writer <EOL> class TestWriterMonad ( unittest . TestCase ) : <EOL> def test_writer_return ( self ) : <EOL> w = Writer . unit ( <NUM_LIT> ) <EOL> self . assertEqual ( w . run ( ) , ( <NUM_LIT> , "<STR_LIT>" ) ) <EOL> def test_writer_unitint_log ( self ) : <EOL> IntWriter = Writer . factory ( "<STR_LIT>" , int ) <EOL> w = IntWriter . unit ( <NUM_LIT> ) <EOL> self . assertEqual ( w . run ( ) , ( <NUM_LIT> , <NUM_LIT:0> ) ) <EOL> def test_writer_monad_bind ( self ) : <EOL> entry = "<STR_LIT>" <EOL> m = Writer . unit ( <NUM_LIT> ) . bind ( lambda x : Writer ( x * <NUM_LIT:10> , entry ) ) <EOL> self . assertEqual ( m , Writer ( <NUM_LIT> , entry ) ) <EOL> def test_writer_monad_law_left_identity ( self ) : <EOL> entry = "<STR_LIT>" <EOL> a = Writer . unit ( <NUM_LIT> ) . bind ( lambda x : Writer ( x + <NUM_LIT> , entry % x ) ) <EOL> b = ( lambda x : Writer ( x + <NUM_LIT> , entry % x ) ) ( <NUM_LIT> ) <EOL> self . assertEqual ( a , b ) <EOL> def test_writer_monad_law_right_identity ( self ) : <EOL> a = Writer . unit ( <NUM_LIT> ) . bind ( Writer . unit ) <EOL> self . assertEqual ( a , Writer . unit ( <NUM_LIT> ) ) <EOL> def test_writer_monad_law_associativity ( self ) : <EOL> add1000 = "<STR_LIT>" <EOL> mul100 = "<STR_LIT>" <EOL> a = Writer . unit ( <NUM_LIT> ) . bind ( <EOL> lambda x : Writer ( x + <NUM_LIT:1000> , add1000 % x ) ) . bind ( <EOL> lambda y : Writer ( y * <NUM_LIT:100> , mul100 % y ) ) <EOL> b = Writer . unit ( <NUM_LIT> ) . bind ( <EOL> lambda x : Writer ( x + <NUM_LIT:1000> , add1000 % x ) . bind ( <EOL> lambda y : Writer ( y * <NUM_LIT:100> , mul100 % y ) <EOL> ) ) <EOL> self . assertEqual ( a , b ) </s>
