Exemplo n.º 1
0
    def setUp(self):
        self.g = Graph()
        self.g.add_connected_vertice(0, 0)
        self.g.add_connected_vertice(3, 4)
        self.g.add_connected_vertice(0, 4)
        self.g.add_connected_vertice(3, 0)
        self.g.add_connected_vertice(10, 40)

        self.mst = [[
            Vertice(0, 0),
            Vertice(0, 4),
            Vertice(3, 0),
            Vertice(3, 4),
            Vertice(10, 40),
        ]]

        self.three_groups = [
            [Vertice(0, 0), Vertice(3, 0)],
            [Vertice(3, 4), Vertice(0, 4)],
            [Vertice(10, 40)],
        ]
Exemplo n.º 2
0
    def test_add_connected_vertice(self):
        vertices = []
        edges = []
        self.assertEqual(self.graph.edges, edges)
        self.assertEqual(self.graph.vertices, vertices)

        self.graph.add_connected_vertice(0, 0)
        vertices.append(Vertice(0, 0))
        self.assertEqual(self.graph.edges, edges)
        self.assertEqual(self.graph.vertices, vertices)

        self.graph.add_connected_vertice(3, 4)
        vertices.append(Vertice(3, 4))
        edges.append(Edge(vertices[0], vertices[1]))
        self.assertEqual(self.graph.edges, edges)

        self.graph.add_connected_vertice(0, 4)
        vertices.append(Vertice(0, 4))
        edges.append(Edge(vertices[0], vertices[2]))
        edges.append(Edge(vertices[1], vertices[2]))
        self.assertEqual(self.graph.edges, edges)
        self.assertEqual(self.graph.vertices, vertices)
Exemplo n.º 3
0
 def setUp(self):
     self.v1 = Vertice(0, 0)
     self.v2 = Vertice(3, 4)
     self.edge = Edge(self.v1, self.v2)
Exemplo n.º 4
0
 def test_repr(self):
     vertice = Vertice(9, 1)
     self.assertEqual(str(vertice), repr(vertice))
Exemplo n.º 5
0
 def test_str(self):
     vertice = Vertice(9, 1)
     self.assertEqual('(9, 1)', str(vertice))
Exemplo n.º 6
0
 def test_euclidian_distance(self):
     v1 = Vertice(0, 0)
     v2 = Vertice(3, 4)
     self.assertEqual(v1 - v2, 5)
Exemplo n.º 7
0
 def test_init(self):
     vertice = Vertice(10, 23)
     self.assertEqual(vertice.x, 10)
     self.assertEqual(vertice.y, 23)