Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved add_node.

  • Loading branch information...
commit 0ab0303e9c892c2697421450306a131450aae086 1 parent afa5864
@rik0 authored
View
2  pynetsym/graph/interface.py
@@ -4,6 +4,8 @@ class IGraph(Interface):
def add_node(self):
"""
Add a node to the graph.
+ @return The index of the newly created node.
+ @rtype int
"""
def add_edge(self, source, target):
View
4 pynetsym/graph/nx_impl.py
@@ -21,7 +21,9 @@ def __init__(self, graph_type=nx.Graph, data=None, **kwargs):
self.nx_graph = graph_type(data=data, **kwargs)
def add_node(self):
- self.nx_graph.add_node(self.index_store.take())
+ node_index = self.index_store.take()
+ self.nx_graph.add_node(node_index)
+ return node_index
def add_edge(self, source, target):
self.nx_graph.add_edge(source, target)
View
1  pynetsym/graph/scipy_impl.py
@@ -29,6 +29,7 @@ def add_node(self):
if node_index >= self._max_nodes():
self._enlarge(node_index)
self._nodes.add(node_index)
+ return node_index
def add_edge(self, source, target):
# consider direct vs. undirected
View
4 tests/test_graph.py
@@ -18,6 +18,6 @@ def testEmpty(self):
self.assertEqual(0, self.graph.number_of_edges())
def testAddedNode(self):
- self.graph.add_node()
+ self.assertEqual(0, self.graph.add_node())
self.assertEqual(1, self.graph.number_of_nodes())
- self.assertEqual(0, self.graph.number_of_edges())
+ self.assertEqual(0, self.graph.number_of_edges())
Please sign in to comment.
Something went wrong with that request. Please try again.