#NEWLINE# def test_morphisms( ) : #NEWLINE# #INDENT# A = Object ( 'A' ) #NEWLINE# B = Object ( 'B' ) #NEWLINE# C = Object ( 'C' ) #NEWLINE# D = Object ( 'D' ) #NEWLINE# f = NamedMorphism ( A , B , 'f' ) #NEWLINE# assert ( f . domain == A ) #NEWLINE# assert ( f . codomain == B ) #NEWLINE# assert ( f == NamedMorphism ( A , B , 'f' ) ) #NEWLINE# id_A = IdentityMorphism ( A ) #NEWLINE# id_B = IdentityMorphism ( B ) #NEWLINE# assert ( id_A . domain == A ) #NEWLINE# assert ( id_A . codomain == A ) #NEWLINE# assert ( id_A == IdentityMorphism ( A ) ) #NEWLINE# assert ( id_A != id_B ) #NEWLINE# g = NamedMorphism ( B , C , 'g' ) #NEWLINE# assert ( g . name == 'g' ) #NEWLINE# assert ( g != f ) #NEWLINE# assert ( g == NamedMorphism ( B , C , 'g' ) ) #NEWLINE# assert ( g != NamedMorphism ( B , C , 'f' ) ) #NEWLINE# assert ( f == CompositeMorphism ( f ) ) #NEWLINE# k = g . compose ( f ) #NEWLINE# assert ( k . domain == A ) #NEWLINE# assert ( k . codomain == C ) #NEWLINE# assert ( k . components == Tuple ( f , g ) ) #NEWLINE# assert ( ( g * f ) == k ) #NEWLINE# assert ( CompositeMorphism ( f , g ) == k ) #NEWLINE# assert ( CompositeMorphism ( ( g * f ) ) == ( g * f ) ) #NEWLINE# h = NamedMorphism ( C , D , 'h' ) #NEWLINE# p = ( h * g ) #NEWLINE# u = ( ( h * g ) * f ) #NEWLINE# assert ( ( h * k ) == u ) #NEWLINE# assert ( ( p * f ) == u ) #NEWLINE# assert ( CompositeMorphism ( f , g , h ) == u ) #NEWLINE# u2 = u . flatten ( 'u' ) #NEWLINE# assert isinstance ( u2 , NamedMorphism ) #NEWLINE# assert ( u2 . name == 'u' ) #NEWLINE# assert ( u2 . domain == A ) #NEWLINE# assert ( u2 . codomain == D ) #NEWLINE# assert ( ( f * id_A ) == f ) #NEWLINE# assert ( ( id_B * f ) == f ) #NEWLINE# assert ( ( id_A * id_A ) == id_A ) #NEWLINE# assert ( CompositeMorphism ( id_A ) == id_A ) #NEWLINE# raises ( ValueError , ( lambda : ( f * g ) ) ) #NEWLINE# raises ( TypeError , ( lambda : f . compose ( None ) ) ) #NEWLINE# raises ( TypeError , ( lambda : id_A . compose ( None ) ) ) #NEWLINE# raises ( TypeError , ( lambda : ( f * None ) ) ) #NEWLINE# raises ( TypeError , ( lambda : ( id_A * None ) ) ) #NEWLINE# raises ( TypeError , ( lambda : CompositeMorphism ( f , None , 1 ) ) ) #NEWLINE# raises ( ValueError , ( lambda : NamedMorphism ( A , B , '' ) ) ) #NEWLINE# raises ( NotImplementedError , ( lambda : Morphism ( A , B ) ) )