  class TestPathExists(object):
  
      def test_path_exists(self):
          nodes = []
          graph = Graph()
          for id in range(0, 6):
              nodes.append(graph.add_node(id))
          graph.add_edge(0, 1, 5)
          graph.add_edge(0, 4, 3)
          graph.add_edge(0, 5, 2)
 
</s> remove     "        graph = Graph()\n",
 </s> add     "        graph = GraphPathExists()\n", </s> remove     "        graph = Graph()\n",
 </s> add     "        graph = GraphPathExists()\n", </s> remove     "        for adj_node in node.adjacent:\n",
    "            if adj_node.visit_state == State.unvisited:\n",
    "                queue.append(adj_node)\n",
    "                adj_node.visit_state = State.visited\n",
    "    return False"
 </s> add     "        queue = deque()\n",
    "        queue.append(start)\n",
    "        start.visit_state = State.visited\n",
    "        while queue:\n",
    "            node = queue.popleft()\n",
    "            if node is end:\n",
    "                return True\n",
    "            for adj_node in node.adj_nodes.values():\n",
    "                if adj_node.visit_state == State.unvisited:\n",
    "                    queue.append(adj_node)\n",
    "                    adj_node.visit_state = State.visited\n",
    "        return False" </s> remove     "def path_exists(start, end):\n",
    "    if start is None or end is None:\n",
    "        return False\n",
    "    if start is end:\n",
    "        return True\n",
    "    queue = deque()\n",
    "    queue.append(start)\n",
    "    start.visit_state = State.visited\n",
    "    while queue:\n",
    "        node = queue.popleft()\n",
    "        if node is end:\n",
 </s> add     "class GraphPathExists(Graph):\n",
    "\n",
    "    def path_exists(self, start, end):\n",
    "        if start is None or end is None:\n",
    "            return False\n",
    "        if start is end:\n", </s> remove         assert_equal(path_exists(nodes[0], nodes[2]), True)
        assert_equal(path_exists(nodes[0], nodes[0]), True)
        assert_equal(path_exists(nodes[4], nodes[5]), False)
 </s> add         assert_equal(graph.path_exists(nodes[0], nodes[2]), True)
        assert_equal(graph.path_exists(nodes[0], nodes[0]), True)
        assert_equal(graph.path_exists(nodes[4], nodes[5]), False)
        graph = GraphPathExists()
  class TestPathExists(object):
  
      def test_path_exists(self):
          nodes = []
        graph = GraphPathExists()
          for id in range(0, 6):
              nodes.append(graph.add_node(id))
          graph.add_edge(0, 1, 5)
          graph.add_edge(0, 4, 3)
          graph.add_edge(0, 5, 2)
keep keep keep keep replace keep keep keep keep keep
 Move graph path exists to a class 
graphs_trees/graph_path_exists/test_path_exists.py