#NEWLINE# def test_copy( self ) : #NEWLINE# #INDENT# self . graph . add_nodes_from ( [ 'a' , 'b' ] ) #NEWLINE# self . graph . add_edges_from ( [ ( 'a' , 'b' ) ] ) #NEWLINE# copy = self . graph . copy ( ) #NEWLINE# self . assertTrue ( copy . check_model ( ) ) #NEWLINE# self . assertEqual ( len ( copy . nodes ( ) ) , 2 ) #NEWLINE# self . assertListEqual ( copy . neighbors ( 'a' ) , [ 'b' ] ) #NEWLINE# self . assertListEqual ( copy . neighbors ( 'b' ) , [ 'a' ] ) #NEWLINE# self . graph . add_nodes_from ( [ 'c' ] ) #NEWLINE# self . graph . add_edges_from ( [ ( 'c' , 'b' ) ] ) #NEWLINE# self . assertEqual ( len ( copy . nodes ( ) ) , 2 ) #NEWLINE# self . assertListEqual ( copy . neighbors ( 'a' ) , [ 'b' ] ) #NEWLINE# self . assertListEqual ( copy . neighbors ( 'b' ) , [ 'a' ] ) #NEWLINE# with self . assertRaises ( nx . NetworkXError ) : #NEWLINE# #INDENT# copy . neighbors ( 'c' ) #NEWLINE# #UNINDENT# self . assertEqual ( len ( copy . get_factors ( ) ) , 0 ) #NEWLINE# phi1 = Factor ( [ 'a' , 'b' ] , [ 2 , 2 ] , [ [ 0.3 , 0.7 ] , [ 0.9 , 0.1 ] ] ) #NEWLINE# self . graph . add_factors ( phi1 ) #NEWLINE# with self . assertRaises ( AssertionError ) : #NEWLINE# #INDENT# self . assertListEqual ( copy . get_factors ( ) , self . graph . get_factors ( ) ) #NEWLINE# #UNINDENT# del copy #NEWLINE# copy = self . graph . copy ( ) #NEWLINE# self . assertListEqual ( copy . get_factors ( ) , self . graph . get_factors ( ) ) #NEWLINE# phi1 . values = np . array ( [ [ 0.5 , 0.5 ] , [ 0.5 , 0.5 ] ] ) #NEWLINE# self . assertNotEqual ( self . graph . get_factors ( ) , copy . get_factors ( ) ) #NEWLINE# del copy #NEWLINE# self . graph . add_nodes_from ( [ 'd' ] ) #NEWLINE# copy = self . graph . copy ( ) #NEWLINE# self . assertEqual ( len ( copy . nodes ( ) ) , 4 ) #NEWLINE# self . assertListEqual ( self . graph . neighbors ( 'a' ) , [ 'b' ] ) #NEWLINE# self . assertTrue ( ( 'a' in self . graph . neighbors ( 'b' ) ) ) #NEWLINE# self . assertTrue ( ( 'c' in self . graph . neighbors ( 'b' ) ) ) #NEWLINE# self . assertListEqual ( self . graph . neighbors ( 'c' ) , [ 'b' ] ) #NEWLINE# self . assertListEqual ( self . graph . neighbors ( 'd' ) , [ ] ) #NEWLINE# copy . add_nodes_from ( [ 'e' ] ) #NEWLINE# self . assertListEqual ( copy . neighbors ( 'e' ) , [ ] ) #NEWLINE# with self . assertRaises ( nx . NetworkXError ) : #NEWLINE# #INDENT# self . graph . neighbors ( 'e' ) #NEWLINE# #UNINDENT# copy . add_edges_from ( [ ( 'd' , 'b' ) ] ) #NEWLINE# self . assertTrue ( ( 'a' in copy . neighbors ( 'b' ) ) ) #NEWLINE# self . assertTrue ( ( 'c' in copy . neighbors ( 'b' ) ) ) #NEWLINE# self . assertTrue ( ( 'd' in copy . neighbors ( 'b' ) ) ) #NEWLINE# self . assertTrue ( ( 'a' in self . graph . neighbors ( 'b' ) ) ) #NEWLINE# self . assertTrue ( ( 'c' in self . graph . neighbors ( 'b' ) ) ) #NEWLINE# self . assertFalse ( ( 'd' in self . graph . neighbors ( 'b' ) ) ) #NEWLINE# copy . remove_factors ( phi1 ) #NEWLINE# self . assertEqual ( len ( self . graph . get_factors ( ) ) , 1 ) #NEWLINE# self . assertEqual ( len ( copy . get_factors ( ) ) , 0 )