@@ -69,20 +69,46 @@ def test_hypergraph_from_bipartite(sbsd_hypergraph):
6969 assert len (HB .nodes ) == 8
7070
7171
72- @pytest .mark .skip ("Deprecated method; will support in later release" )
73- def test_add_node_to_edge (sbs ):
74- H = Hypergraph (sbs .edgedict )
75- assert H .shape == (7 , 6 )
76- node = "B"
77- edge = "P"
78- H .add_node_to_edge (node , edge )
79- assert H .shape == (8 , 6 )
80- # add edge with nodes already in hypergraph
81- H .add_edge ({"Z" : ["A" , "B" ]})
82- assert H .shape == (8 , 7 )
83- # add edge not in hypergraph with nodes not in hypergraph
84- H .add_edge ({"Y" : ["M" , "N" ]})
85- assert H .shape == (10 , 8 )
72+ def test_add_edge_inplace (sbs ):
73+ h = Hypergraph (sbs .edgedict )
74+ assert h .shape == (7 , 6 )
75+
76+ # add a new edge in place; i.e. the current hypergraph should be mutated
77+ new_edge = "X"
78+ h .add_edge (new_edge )
79+
80+ # the Hypergraph should not increase its number of edges and incidences because the current behavior of adding
81+ # an edge does not connect two or more nodes.
82+ # In other words, adding an edge with no nodes
83+ assert h .shape == (7 , 6 )
84+ assert new_edge not in h .edges .elements
85+
86+ # the new edge has no user-defined property data, so it should not be listed in the PropertyStore
87+ assert new_edge not in h .edges .properties
88+
89+ # However, the new_edge will be listed in the complete list of all user and non-user-define properties for all edges
90+ assert new_edge in h .edges .to_dataframe .index .tolist ()
91+
92+ assert new_edge in h .edges .to_dataframe .index .tolist ()
93+
94+
95+ def test_add_edge_not_inplace (sbs ):
96+ h = Hypergraph (sbs .edgedict )
97+ assert h .shape == (7 , 6 )
98+
99+ # add a new edge not in place; the current hypergraph should be diffrent from the new hypergraph
100+ # created from add_edge
101+ new_edge = "X"
102+ new_hg = h .add_edge (new_edge , inplace = False )
103+
104+ assert new_hg .shape == (7 , 6 )
105+ assert new_edge not in new_hg .edges .elements
106+
107+ assert new_edge not in new_hg .edges .properties
108+ assert new_edge in new_hg .edges .to_dataframe .index .tolist ()
109+
110+ # verify that the new edge is not in the old HyperGraph
111+ assert new_edge not in h .edges .to_dataframe .index .tolist ()
86112
87113
88114def test_remove_edges (sbs ):
0 commit comments