Skip to content
Browse files

Improved add_node.

  • Loading branch information...
1 parent afa5864 commit 0ab0303e9c892c2697421450306a131450aae086 @rik0 committed Sep 21, 2012
Showing with 8 additions and 3 deletions.
  1. +2 −0 pynetsym/graph/interface.py
  2. +3 −1 pynetsym/graph/nx_impl.py
  3. +1 −0 pynetsym/graph/scipy_impl.py
  4. +2 −2 tests/test_graph.py
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())

0 comments on commit 0ab0303

Please sign in to comment.
Something went wrong with that request. Please try again.