Exemple #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)],
        ]
Exemple #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)
Exemple #3
0
 def setUp(self):
     self.v1 = Vertice(0, 0)
     self.v2 = Vertice(3, 4)
     self.edge = Edge(self.v1, self.v2)
Exemple #4
0
 def test_repr(self):
     vertice = Vertice(9, 1)
     self.assertEqual(str(vertice), repr(vertice))
Exemple #5
0
 def test_str(self):
     vertice = Vertice(9, 1)
     self.assertEqual('(9, 1)', str(vertice))
Exemple #6
0
 def test_euclidian_distance(self):
     v1 = Vertice(0, 0)
     v2 = Vertice(3, 4)
     self.assertEqual(v1 - v2, 5)
Exemple #7
0
 def test_init(self):
     vertice = Vertice(10, 23)
     self.assertEqual(vertice.x, 10)
     self.assertEqual(vertice.y, 23)