Update graph remove_neighbor error handling (#93)

This commit is contained in:
Donne Martin
2016-07-20 07:29:48 -04:00
committed by GitHub
parent 0e866dc7c0
commit 113eddd3c3
2 changed files with 8 additions and 14 deletions

View File

@@ -30,14 +30,11 @@ class Node:
self.adj_nodes[neighbor.key] = neighbor
def remove_neighbor(self, neighbor):
if neighbor is None:
raise Exception('Invalid neighbor')
if neighbor.key in self.adj_nodes:
neighbor.incoming_edges -= 1
del self.adj_weights[neighbor.key]
del self.adj_nodes[neighbor.key]
else:
if neighbor is None or neighbor.key not in self.adj_nodes:
raise Exception('Invalid neighbor')
neighbor.incoming_edges -= 1
del self.adj_weights[neighbor.key]
del self.adj_nodes[neighbor.key]
class Graph: