text: import unittest
  from abc import abstractmethod, ABCMeta
  
  from tests.graph_impl import AbstractNode, AbstractEdge
  
  
  class PathTest(metaclass=ABCMeta):
  
      @abstractmethod
      def setDirectedPath(self):
          raise NotImplementedError
      
      @abstractmethod
      def setUndirectedPath(self):
          raise NotImplementedError
  
      def test_add_edge_front_directed(self):
          self.setDirectedPath()
          node1 = AbstractNode(1)
          node2 = AbstractNode(2)
          node3 = AbstractNode(3)
          node4 = AbstractNode(4)
          node5 = AbstractNode(5)
          edge1 = AbstractEdge(1, node1, node2)
          edge2 = AbstractEdge(2, node2, node3)
          edge3 = AbstractEdge(3, node3, node4)
          edge4 = AbstractEdge(4, node4, node5)
          self.assertEqual(0, len(self.path.getEdges()))
          self.assertEqual(0, len(self.path.getNodes()))
          self.assertTrue(self.path.addFirstEdge(edge4))
          self.assertEqual(1, len(self.path.getEdges()))
          self.assertEqual(2, len(self.path.getNodes()))
          self.assertTrue(self.path.addFirstEdge(edge3))
          self.assertEqual(2, len(self.path.getEdges()))
          self.assertEqual(3, len(self.path.getNodes()))
          self.assertTrue(self.path.addFirst([edge1, edge2]))
          self.assertEqual(4, len(self.path.getEdges()))
          self.assertEqual(5, len(self.path.getNodes()))
  
      def test_add_edge_end_directed(self):
          self.setDirectedPath()
          node1 = AbstractNode(1)
          node2 = AbstractNode(2)
          node3 = AbstractNode(3)
          node4 = AbstractNode(4)
          node5 = AbstractNode(5)
          edge1 = AbstractEdge(1, node1, node2)
          edge2 = AbstractEdge(2, node2, node3)
          edge3 = AbstractEdge(3, node3, node4)
          edge4 = AbstractEdge(4, node4, node5)
          self.assertEqual(0, len(self.path.getEdges()))
          self.assertEqual(0, len(self.path.getNodes()))
          self.assertTrue(self.path.addLastEdge(edge1))
          self.assertEqual(1, len(self.path.getEdges()))
          self.assertEqual(2, len(self.path.getNodes()))
          self.assertTrue(self.path.addLastEdge(edge2))
          self.assertEqual(2, len(self.path.getEdges()))
          self.assertEqual(3, len(self.path.getNodes()))
          self.assertTrue(self.path.addLast([edge3, edge4]))
          self.assertEqual(4, len(self.path.getEdges()))
          self.assertEqual(5, len(self.path.getNodes()))
  
      def test_remove_edge_front_directed(self):
          self.setDirectedPath()
          node1 = AbstractNode(1)
          node2 = AbstractNode(2)
          node3 = AbstractNode(3)
          node4 = AbstractNode(4)
          node5 = AbstractNode(5)
          edge1 = AbstractEdge(1, node1, node2)
          edge2 = AbstractEdge(2, node2, node3)
          edge3 = AbstractEdge(3, node3, node4)
          edge4 = AbstractEdge(4, node4, node5)
          self.assertTrue(self.path.addFirstEdge(edge4))
          self.assertTrue(self.path.addFirstEdge(edge3))
          self.assertTrue(self.path.addFirst([edge1, edge2]))
          self.assertEqual(4, len(self.path.getEdges()))
          self.assertEqual(5, len(self.path.getNodes()))
          self.assertTrue(self.path.removeEdge(edge1))
          self.assertEqual(3, len(self.path.getEdges()))
          self.assertEqual(4, len(self.path.getNodes()))
          self.assertTrue(self.path.remove([edge2, edge3]))
          self.assertEqual(1, len(self.path.getEdges()))
          self.assertEqual(2, len(self.path.getNodes()))
  
      def test_remove_edge_end_directed(self):
          self.setDirectedPath()
          node1 = AbstractNode(1)
          node2 = AbstractNode(2)
          node3 = AbstractNode(3)
          node4 = AbstractNode(4)
          node5 = AbstractNode(5)
          edge1 = AbstractEdge(1, node1, node2)
          edge2 = AbstractEdge(2, node2, node3)
          edge3 = AbstractEdge(3, node3, node4)
          edge4 = AbstractEdge(4, node4, node5)
          self.assertTrue(self.path.addFirstEdge(edge4))
          self.assertTrue(self.path.addFirstEdge(edge3))
          self.assertTrue(self.path.addFirst([edge1, edge2]))
          self.assertEqual(4, len(self.path.getEdges()))
          self.assertEqual(5, len(self.path.getNodes()))
          self.assertTrue(self.path.removeEdge(edge4))
          self.assertEqual(3, len(self.path.getEdges()))
          self.assertEqual(4, len(self.path.getNodes()))
          self.assertTrue(self.path.remove([edge3, edge2]))
          self.assertEqual(1, len(self.path.getEdges()))
          self.assertEqual(2, len(self.path.getNodes()))
  
      def test_add_edge_front_undirected(self):
          self.setUndirectedPath()
          node1 = AbstractNode(1)
          node2 = AbstractNode(2)
          node3 = AbstractNode(3)
          node4 = AbstractNode(4)
          node5 = AbstractNode(5)
          edge1 = AbstractEdge(1, node2, node1)
          edge2 = AbstractEdge(2, node2, node3)
          edge3 = AbstractEdge(3, node4, node3)
          edge4 = AbstractEdge(4, node4, node5)
          self.assertEqual(0, len(self.path.getEdges()))
          self.assertEqual(0, len(self.path.getNodes()))
          self.assertTrue(self.path.addFirstEdge(edge4))
          self.assertEqual(1, len(self.path.getEdges()))
          self.assertEqual(2, len(self.path.getNodes()))
          self.assertTrue(self.path.addFirstEdge(edge3))
          self.assertEqual(2, len(self.path.getEdges()))
          self.assertEqual(3, len(self.path.getNodes()))
          self.assertTrue(self.path.addFirst([edge1, edge2]))
          self.assertEqual(4, len(self.path.getEdges()))
          self.assertEqual(5, len(self.path.getNodes()))
  
      def test_add_edge_end_undirected(self):
          self.setUndirectedPath()
          node1 = AbstractNode(1)
          node2 = AbstractNode(2)
          node3 = AbstractNode(3)
          node4 = AbstractNode(4)
          node5 = AbstractNode(5)
          edge1 = AbstractEdge(1, node2, node1)
          edge2 = AbstractEdge(2, node2, node3)
          edge3 = AbstractEdge(3, node4, node3)
          edge4 = AbstractEdge(4, node4, node5)
          self.assertEqual(0, len(self.path.getEdges()))
          self.assertEqual(0, len(self.path.getNodes()))
          self.assertTrue(self.path.addLastEdge(edge1))
          self.assertEqual(1, len(self.path.getEdges()))
          self.assertEqual(2, len(self.path.getNodes()))
          self.assertTrue(self.path.addLastEdge(edge2))
          self.assertEqual(2, len(self.path.getEdges()))
          self.assertEqual(3, len(self.path.getNodes()))
          self.assertTrue(self.path.addLast([edge3, edge4]))
          self.assertEqual(4, len(self.path.getEdges()))
          self.assertEqual(5, len(self.path.getNodes()))
  
      def test_remove_edge_front_undirected(self):
          self.setUndirectedPath()
          node1 = AbstractNode(1)
          node2 = AbstractNode(2)
          node3 = AbstractNode(3)
          node4 = AbstractNode(4)
          node5 = AbstractNode(5)
          edge1 = AbstractEdge(1, node2, node1)
          edge2 = AbstractEdge(2, node2, node3)
          edge3 = AbstractEdge(3, node4, node3)
          edge4 = AbstractEdge(4, node4, node5)
          self.assertTrue(self.path.addFirstEdge(edge4))
          self.assertTrue(self.path.addFirstEdge(edge3))
          self.assertTrue(self.path.addFirst([edge1, edge2]))
          self.assertEqual(4, len(self.path.getEdges()))
          self.assertEqual(5, len(self.path.getNodes()))
          self.assertTrue(self.path.removeEdge(edge1))
          self.assertEqual(3, len(self.path.getEdges()))
          self.assertEqual(4, len(self.path.getNodes()))
          self.assertTrue(self.path.remove([edge2, edge3]))
          self.assertEqual(1, len(self.path.getEdges()))
          self.assertEqual(2, len(self.path.getNodes()))
  
      def test_remove_edge_end_undirected(self):
          self.setUndirectedPath()
          node1 = AbstractNode(1)
          node2 = AbstractNode(2)
          node3 = AbstractNode(3)
          node4 = AbstractNode(4)
          node5 = AbstractNode(5)
          edge1 = AbstractEdge(1, node2, node1)
          edge2 = AbstractEdge(2, node2, node3)
          edge3 = AbstractEdge(3, node4, node3)
          edge4 = AbstractEdge(4, node4, node5)
          self.assertTrue(self.path.addFirstEdge(edge4))
          self.assertTrue(self.path.addFirstEdge(edge3))
          self.assertTrue(self.path.addFirst([edge1, edge2]))
          self.assertEqual(4, len(self.path.getEdges()))
          self.assertEqual(5, len(self.path.getNodes()))
          self.assertTrue(self.path.removeEdge(edge4))
          self.assertEqual(3, len(self.path.getEdges()))
          self.assertEqual(4, len(self.path.getNodes()))
          self.assertTrue(self.path.remove([edge2, edge3]))
          self.assertEqual(1, len(self.path.getEdges()))
          self.assertEqual(2, len(self.path.getNodes()))
  
      def test_cannot_add_unfitting_edge_directed(self):
          self.setDirectedPath()
          node1 = AbstractNode(1)
          node2 = AbstractNode(2)
          node3 = AbstractNode(3)
          edge1 = AbstractEdge(1, node2, node1)
          edge2 = AbstractEdge(2, node2, node3)
          self.assertTrue(self.path.addFirstEdge(edge1))
          self.assertEqual(2, len(self.path.getNodes()))
          self.assertEqual(1, len(self.path.getEdges()))
          self.assertFalse(self.path.addFirstEdge(edge2))
          # The self.path should remain the same
          self.assertEqual(2, len(self.path.getNodes()))
          self.assertEqual(1, len(self.path.getEdges()))
  
      def test_cannot_add_unfitting_edge_undirected(self):
          self.setUndirectedPath()
          node1 = AbstractNode(1)
          node2 = AbstractNode(2)
          node3 = AbstractNode(3)
          node4 = AbstractNode(4)
          edge1 = AbstractEdge(2, node3, node2)
          edge2 = AbstractEdge(1, node2, node1)
          edge3 = AbstractEdge(3, node3, node4)
          self.assertTrue(self.path.addFirst([edge1, edge2]))
          self.assertEqual(3, len(self.path.getNodes()))
          self.assertEqual(2, len(self.path.getEdges()))
          self.assertFalse(self.path.addLastEdge(edge3))
          # The self.path should remain the same
          self.assertEqual(3, len(self.path.getNodes()))
          self.assertEqual(2, len(self.path.getEdges()))
  
      def test_will_reset_unfitting_path(self):
          self.setDirectedPath()
          node1 = AbstractNode(1)
          node2 = AbstractNode(2)
          node3 = AbstractNode(3)
          node4 = AbstractNode(4)
          node5 = AbstractNode(5)
          edge1 = AbstractEdge(1, node1, node2)
          edge2 = AbstractEdge(2, node2, node3)
          edge3 = AbstractEdge(3, node3, node4)
          edge4 = AbstractEdge(4, node4, node5)
          self.assertTrue(self.path.addFirstEdge(edge1))
          self.assertEqual(1, len(self.path.getEdges()))
          self.assertEqual(2, len(self.path.getNodes()))
          self.assertFalse(self.path.addLast([edge2, edge4]))
          self.assertEqual(1, len(self.path.getEdges()))
          self.assertEqual(2, len(self.path.getNodes()))
  
  