#NEWLINE# def test_diagram( ) : #NEWLINE# #INDENT# A = Object ( 'A' ) #NEWLINE# B = Object ( 'B' ) #NEWLINE# C = Object ( 'C' ) #NEWLINE# f = NamedMorphism ( A , B , 'f' ) #NEWLINE# g = NamedMorphism ( B , C , 'g' ) #NEWLINE# id_A = IdentityMorphism ( A ) #NEWLINE# id_B = IdentityMorphism ( B ) #NEWLINE# empty = EmptySet ( ) #NEWLINE# d1 = Diagram ( [ f ] ) #NEWLINE# assert ( d1 . objects == FiniteSet ( A , B ) ) #NEWLINE# assert ( d1 . hom ( A , B ) == ( FiniteSet ( f ) , empty ) ) #NEWLINE# assert ( d1 . hom ( A , A ) == ( FiniteSet ( id_A ) , empty ) ) #NEWLINE# assert ( d1 . hom ( B , B ) == ( FiniteSet ( id_B ) , empty ) ) #NEWLINE# assert ( d1 == Diagram ( [ id_A , f ] ) ) #NEWLINE# assert ( d1 == Diagram ( [ f , f ] ) ) #NEWLINE# d2 = Diagram ( [ f , g ] ) #NEWLINE# homAC = d2 . hom ( A , C ) [ 0 ] #NEWLINE# assert ( d2 . objects == FiniteSet ( A , B , C ) ) #NEWLINE# assert ( ( g * f ) in d2 . premises . keys ( ) ) #NEWLINE# assert ( homAC == FiniteSet ( ( g * f ) ) ) #NEWLINE# d11 = Diagram ( [ f ] ) #NEWLINE# assert ( d1 == d11 ) #NEWLINE# assert ( d1 != d2 ) #NEWLINE# assert ( hash ( d1 ) == hash ( d11 ) ) #NEWLINE# d11 = Diagram ( { #NEWLINE# #INDENT# f : 'unique' , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert ( d1 != d11 ) #NEWLINE# d = Diagram ( [ f , g ] , { #NEWLINE# #INDENT# ( g * f ) : 'unique' , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert ( d . conclusions == Dict ( { #NEWLINE# #INDENT# ( g * f ) : FiniteSet ( 'unique' ) , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# assert ( d . hom ( A , C ) == ( FiniteSet ( ( g * f ) ) , FiniteSet ( ( g * f ) ) ) ) #NEWLINE# d = Diagram ( [ f , g ] , [ ( g * f ) ] ) #NEWLINE# assert ( d . hom ( A , C ) == ( FiniteSet ( ( g * f ) ) , FiniteSet ( ( g * f ) ) ) ) #NEWLINE# d = Diagram ( { #NEWLINE# #INDENT# f : [ 'unique' , 'isomorphism' ] , #NEWLINE# g : 'unique' , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert ( d . premises [ ( g * f ) ] == FiniteSet ( 'unique' ) ) #NEWLINE# d = Diagram ( [ f ] , [ g ] ) #NEWLINE# assert ( d . conclusions == Dict ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ) #NEWLINE# d = Diagram ( ) #NEWLINE# assert ( d . premises == Dict ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ) #NEWLINE# assert ( d . conclusions == Dict ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ) #NEWLINE# assert ( d . objects == empty ) #NEWLINE# d = Diagram ( Dict ( { #NEWLINE# #INDENT# f : FiniteSet ( 'unique' , 'isomorphism' ) , #NEWLINE# g : 'unique' , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# assert ( d . premises [ ( g * f ) ] == FiniteSet ( 'unique' ) ) #NEWLINE# d = Diagram ( [ ( g * f ) ] ) #NEWLINE# assert ( f in d . premises ) #NEWLINE# assert ( g in d . premises ) #NEWLINE# d = Diagram ( [ f , g ] , { #NEWLINE# #INDENT# ( g * f ) : 'unique' , #NEWLINE# #UNINDENT# } ) #NEWLINE# d1 = Diagram ( [ f ] ) #NEWLINE# assert d . is_subdiagram ( d1 ) #NEWLINE# assert ( not d1 . is_subdiagram ( d ) ) #NEWLINE# d = Diagram ( [ NamedMorphism ( B , A , "f'" ) ] ) #NEWLINE# assert ( not d . is_subdiagram ( d1 ) ) #NEWLINE# assert ( not d1 . is_subdiagram ( d ) ) #NEWLINE# d1 = Diagram ( [ f , g ] , { #NEWLINE# #INDENT# ( g * f ) : [ 'unique' , 'something' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert ( not d . is_subdiagram ( d1 ) ) #NEWLINE# assert ( not d1 . is_subdiagram ( d ) ) #NEWLINE# d = Diagram ( { #NEWLINE# #INDENT# f : 'blooh' , #NEWLINE# #UNINDENT# } ) #NEWLINE# d1 = Diagram ( { #NEWLINE# #INDENT# f : 'bleeh' , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert ( not d . is_subdiagram ( d1 ) ) #NEWLINE# assert ( not d1 . is_subdiagram ( d ) ) #NEWLINE# d = Diagram ( [ f , g ] , { #NEWLINE# #INDENT# f : 'unique' , #NEWLINE# ( B * f ) : 'veryunique' , #NEWLINE# #UNINDENT# } ) #NEWLINE# d1 = d . subdiagram_from_objects ( FiniteSet ( A , B ) ) #NEWLINE# assert ( d1 == Diagram ( [ f ] , { #NEWLINE# #INDENT# f : 'unique' , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# raises ( ValueError , ( lambda : d . subdiagram_from_objects ( FiniteSet ( A , Object ( 'D' ) ) ) ) ) #NEWLINE# raises ( ValueError , ( lambda : Diagram ( { #NEWLINE# #INDENT# IdentityMorphism ( A ) : 'unique' , #NEWLINE# #UNINDENT# } ) ) )