mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-10 19:38:02 +00:00
Reworked graph challenge.
This commit is contained in:
@@ -5,8 +5,8 @@ class TestGraph(object):
|
||||
|
||||
def test_graph(self):
|
||||
graph = Graph()
|
||||
for key in range(0, 6):
|
||||
graph.add_node(key)
|
||||
for id in range(0, 6):
|
||||
graph.add_node(id)
|
||||
graph.add_edge(0, 1, 5)
|
||||
graph.add_edge(0, 5, 2)
|
||||
graph.add_edge(1, 2, 3)
|
||||
@@ -17,15 +17,15 @@ class TestGraph(object):
|
||||
graph.add_edge(5, 4, 8)
|
||||
graph.add_edge(5, 2, 9)
|
||||
|
||||
assert_equal(graph.nodes[0].connections[graph.nodes[1]], 5)
|
||||
assert_equal(graph.nodes[0].connections[graph.nodes[5]], 2)
|
||||
assert_equal(graph.nodes[1].connections[graph.nodes[2]], 3)
|
||||
assert_equal(graph.nodes[2].connections[graph.nodes[3]], 4)
|
||||
assert_equal(graph.nodes[3].connections[graph.nodes[4]], 5)
|
||||
assert_equal(graph.nodes[3].connections[graph.nodes[5]], 6)
|
||||
assert_equal(graph.nodes[4].connections[graph.nodes[0]], 7)
|
||||
assert_equal(graph.nodes[5].connections[graph.nodes[4]], 8)
|
||||
assert_equal(graph.nodes[5].connections[graph.nodes[2]], 9)
|
||||
assert_equal(graph.nodes[0].adjacent[graph.nodes[1]], 5)
|
||||
assert_equal(graph.nodes[0].adjacent[graph.nodes[5]], 2)
|
||||
assert_equal(graph.nodes[1].adjacent[graph.nodes[2]], 3)
|
||||
assert_equal(graph.nodes[2].adjacent[graph.nodes[3]], 4)
|
||||
assert_equal(graph.nodes[3].adjacent[graph.nodes[4]], 5)
|
||||
assert_equal(graph.nodes[3].adjacent[graph.nodes[5]], 6)
|
||||
assert_equal(graph.nodes[4].adjacent[graph.nodes[0]], 7)
|
||||
assert_equal(graph.nodes[5].adjacent[graph.nodes[4]], 8)
|
||||
assert_equal(graph.nodes[5].adjacent[graph.nodes[2]], 9)
|
||||
|
||||
print('Success: test_graph')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user