Ejemplo n.º 1
0
    def test_entry_rich_comparison(self):
        """
        Test of rich comparison operators.
        """
        elem1 = entry.Entry()
        elem2 = entry.Entry()
        elem3 = entry.Entry()

        elem1.discovered = True
        elem1.distance = 10
        elem1.predecessor = 15

        elem2.discovered = False
        elem2.distance = 5
        elem2.predecessor = 3

        elem3.discovered = True
        elem3.distance = 7
        elem3.predecessor = 12

        ref = [elem2, elem3, elem1]
        rsorted = [elem1, elem2, elem3]
        rsorted = sorted(rsorted,
                         key=lambda e:
                         (e.discovered, e.distance, e.predecessor))
        self.assertEqual(ref, rsorted)
Ejemplo n.º 2
0
 def setUp(self):
     self.elem1 = entry.Entry()
     self.elem2 = entry.Entry()
     self.elem3 = entry.Entry()
     self.elem3.discovered = True
     self.elem4 = entry.Entry()
     self.elem4.discovered = True
     self.elem4.distance = 100
     self.elem4.predecessor = 10
    def test_graph_algorithms_dijkstra_v6(self):
        """
        Test of Dijkstras algorithm.
        """
        e60 = graph_edge.DirectedWeightedGraphEdge(self.graph2, self.v6_g2,
                                                   self.v0_g2, 7)
        e01 = graph_edge.DirectedWeightedGraphEdge(self.graph2, self.v0_g2,
                                                   self.v1_g2, 7)
        e12 = graph_edge.DirectedWeightedGraphEdge(self.graph2, self.v1_g2,
                                                   self.v2_g2, 2)
        e23 = graph_edge.DirectedWeightedGraphEdge(self.graph2, self.v2_g2,
                                                   self.v3_g2, 2)
        e64 = graph_edge.DirectedWeightedGraphEdge(self.graph2, self.v6_g2,
                                                   self.v4_g2, 1)
        e45 = graph_edge.DirectedWeightedGraphEdge(self.graph2, self.v4_g2,
                                                   self.v5_g2, 6)

        elem0 = entry.Entry(True, 7, self.v6_g2, e60)
        elem1 = entry.Entry(True, 14, self.v0_g2, e01)
        elem2 = entry.Entry(True, 16, self.v1_g2, e12)
        elem3 = entry.Entry(True, 18, self.v2_g2, e23)
        elem4 = entry.Entry(True, 1, self.v6_g2, e64)
        elem5 = entry.Entry(True, 7, self.v4_g2, e45)
        elem6 = entry.Entry(True, 0, None, None)

        ref = array_list.ArrayList(self.graph2.get_number_of_vertices())
        ref[0] = elem0
        ref[1] = elem1
        ref[2] = elem2
        ref[3] = elem3
        ref[4] = elem4
        ref[5] = elem5
        ref[6] = elem6
        res = graph_algorithms.GraphAlgorithms.dijkstras_algorithm(
            self.graph2, self.v6_g2)
        self.assertEqual(ref, res)