Exemplo n.º 1
0
 def test_add_connections(self):
     graph = Graph()
     graph.add_node(Node([0.0, 0.0]))
     graph.add_node(Node([0.0, 0.5]))
     graph.add_node(Node([1.0, 5.0]))
     con1 = GraphConnection(0, 1, 10)
     graph.add_connection(con1)
     self.assertEqual(1, len(graph.get_connections_from_node(0)))
     self.assertEqual(0, len(graph.get_connections_from_node(1)))
     self.assertEqual(0, len(graph.get_connections_from_node(2)))
Exemplo n.º 2
0
 def test_invalid_node_for_connection(self):
     graph = Graph()
     graph.add_node(Node([0.0, 0.0]))
     con1 = GraphConnection(0, 1, 10)
     with self.assertRaises(IndexError) as context:
         graph.add_connection(con1)
         self.assertTrue('IndexError' in str(context.exception))
Exemplo n.º 3
0
 def setUp(self):
     self.graph = Graph()
Exemplo n.º 4
0
 def test_print_connections(self):
     graph = Graph()
     graph.add_node(Node([0.0, 0.0]))
     graph.add_node(Node([0.0, 0.5]))
     graph.add_node(Node([1.0, 5.0]))
     con1 = GraphConnection(0, 1, 10)
     graph.add_connection(con1)
     con1 = GraphConnection(0, 2, 30)
     graph.add_connection(con1)
     self.assertEqual(2, len(graph.get_connections_from_node(0)))
     self.assertEqual(0, len(graph.get_connections_from_node(1)))
     self.assertEqual(0, len(graph.get_connections_from_node(2)))
     for con in graph.get_connections_from_node(0):
         print("From {} to {} cost {}".format(con.get_from_node(),
                                              con.get_to_node(),
                                              con.get_cost()))
Exemplo n.º 5
0
 def test_add_nodes(self):
     graph = Graph()
     graph.add_node(Node([0.0, 0.0]))
     graph.add_node(Node([0.0, 0.5]))
     graph.add_node(Node([1.0, 5.0]))
     self.assertEqual(3, len(graph.get_nodes()))
Exemplo n.º 6
0
 def test_get_nodes_empty(self):
     graph = Graph()
     self.assertEqual([], graph.get_nodes())
Exemplo n.º 7
0
 def test_get_connections_from_node(self):
     graph = Graph()
     graph.add_node(Node([0.0, 0.0]))
     self.assertEqual([], graph.get_connections_from_node(0))