mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-10 03:18:02 +00:00
Move graph path exists to a class
This commit is contained in:
@@ -106,9 +106,11 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def path_exists(start, end):\n",
|
||||
" # TODO: Implement me\n",
|
||||
" pass"
|
||||
"class GraphPathExists(Graph):\n",
|
||||
"\n",
|
||||
" def path_exists(self, start, end):\n",
|
||||
" # TODO: Implement me\n",
|
||||
" pass"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -141,7 +143,7 @@
|
||||
"\n",
|
||||
" def test_path_exists(self):\n",
|
||||
" nodes = []\n",
|
||||
" graph = Graph()\n",
|
||||
" graph = GraphPathExists()\n",
|
||||
" for id in range(0, 6):\n",
|
||||
" nodes.append(graph.add_node(id))\n",
|
||||
" graph.add_edge(0, 1, 5)\n",
|
||||
@@ -153,9 +155,9 @@
|
||||
" graph.add_edge(3, 2, 7)\n",
|
||||
" graph.add_edge(3, 4, 8)\n",
|
||||
"\n",
|
||||
" assert_equal(path_exists(nodes[0], nodes[2]), True)\n",
|
||||
" assert_equal(path_exists(nodes[0], nodes[0]), True)\n",
|
||||
" assert_equal(path_exists(nodes[4], nodes[5]), False)\n",
|
||||
" assert_equal(graph.path_exists(nodes[0], nodes[2]), True)\n",
|
||||
" assert_equal(graph.path_exists(nodes[0], nodes[0]), True)\n",
|
||||
" assert_equal(graph.path_exists(nodes[4], nodes[5]), False)\n",
|
||||
"\n",
|
||||
" print('Success: test_path_exists')\n",
|
||||
"\n",
|
||||
|
||||
Reference in New Issue
Block a user