#NEWLINE# def test_union_all_and_compose_all( ) : #NEWLINE# #INDENT# K3 = nx . complete_graph ( 3 ) #NEWLINE# P3 = nx . path_graph ( 3 ) #NEWLINE# G1 = nx . DiGraph ( ) #NEWLINE# G1 . add_edge ( 'A' , 'B' ) #NEWLINE# G1 . add_edge ( 'A' , 'C' ) #NEWLINE# G1 . add_edge ( 'A' , 'D' ) #NEWLINE# G2 = nx . DiGraph ( ) #NEWLINE# G2 . add_edge ( '1' , '2' ) #NEWLINE# G2 . add_edge ( '1' , '3' ) #NEWLINE# G2 . add_edge ( '1' , '4' ) #NEWLINE# G = nx . union_all ( [ G1 , G2 ] ) #NEWLINE# H = nx . compose_all ( [ G1 , G2 ] ) #NEWLINE# assert_edges_equal ( G . edges ( ) , H . edges ( ) ) #NEWLINE# assert_false ( G . has_edge ( 'A' , '1' ) ) #NEWLINE# assert_raises ( nx . NetworkXError , nx . union , K3 , P3 ) #NEWLINE# H1 = nx . union_all ( [ H , G1 ] , rename = ( 'H' , 'G1' ) ) #NEWLINE# assert_equal ( sorted ( H1 . nodes ( ) ) , [ 'G1A' , 'G1B' , 'G1C' , 'G1D' , 'H1' , 'H2' , 'H3' , 'H4' , 'HA' , 'HB' , 'HC' , 'HD' ] ) #NEWLINE# H2 = nx . union_all ( [ H , G2 ] , rename = ( 'H' , '' ) ) #NEWLINE# assert_equal ( sorted ( H2 . nodes ( ) ) , [ '1' , '2' , '3' , '4' , 'H1' , 'H2' , 'H3' , 'H4' , 'HA' , 'HB' , 'HC' , 'HD' ] ) #NEWLINE# assert_false ( H1 . has_edge ( 'NB' , 'NA' ) ) #NEWLINE# G = nx . compose_all ( [ G , G ] ) #NEWLINE# assert_edges_equal ( G . edges ( ) , H . edges ( ) ) #NEWLINE# G2 = nx . union_all ( [ G2 , G2 ] , rename = ( '' , 'copy' ) ) #NEWLINE# assert_equal ( sorted ( G2 . nodes ( ) ) , [ '1' , '2' , '3' , '4' , 'copy1' , 'copy2' , 'copy3' , 'copy4' ] ) #NEWLINE# assert_equal ( G2 . neighbors ( 'copy4' ) , [ ] ) #NEWLINE# assert_equal ( sorted ( G2 . neighbors ( 'copy1' ) ) , [ 'copy2' , 'copy3' , 'copy4' ] ) #NEWLINE# assert_equal ( len ( G ) , 8 ) #NEWLINE# assert_equal ( nx . number_of_edges ( G ) , 6 ) #NEWLINE# E = nx . disjoint_union_all ( [ G , G ] ) #NEWLINE# assert_equal ( len ( E ) , 16 ) #NEWLINE# assert_equal ( nx . number_of_edges ( E ) , 12 ) #NEWLINE# E = nx . disjoint_union_all ( [ G1 , G2 ] ) #NEWLINE# assert_equal ( sorted ( E . nodes ( ) ) , [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ] ) #NEWLINE# G1 = nx . DiGraph ( ) #NEWLINE# G1 . add_edge ( 'A' , 'B' ) #NEWLINE# G2 = nx . DiGraph ( ) #NEWLINE# G2 . add_edge ( 1 , 2 ) #NEWLINE# G3 = nx . DiGraph ( ) #NEWLINE# G3 . add_edge ( 11 , 22 ) #NEWLINE# G4 = nx . union_all ( [ G1 , G2 , G3 ] , rename = ( 'G1' , 'G2' , 'G3' ) ) #NEWLINE# assert_equal ( sorted ( G4 . nodes ( ) ) , [ 'G1A' , 'G1B' , 'G21' , 'G22' , 'G311' , 'G322' ] )