def test_single_node_edge(): graph = Graph() a = graph.add_node('a') graph.add_edge(a, a) actual = graph.get_neighbors(a) expected = [{'Value': 'a', 'Weight': 1}] assert actual == expected
def __getitem__(self, item): data = self.ann[item] dependencies = data['depends'] g = Graph() for dep in dependencies: gov_node = g.add_node(dep['governorGloss'], dep['governor'], "") dep_node = g.add_node(dep['dependentGloss'], dep['dependent'], "") g.add_edge(gov_node, dep_node, dep['dep']) tree = g.to_tree() tree.padding() for n in tree.nodes.values(): word_idx = self.vocab( n.lex.lower() if n.lex != "<EOB>" else "<EOB>") n.word_idx = word_idx fc_feat = np.load( os.path.join(self.cocotalk_fc, str(data['img_id']) + '.npy')) if self.caption_model == 'att_model' or self.caption_model == 'tree_model_md_att': att_feat = np.load( os.path.join(self.cocotalk_att, str(data['img_id']) + '.npz'))['feat'] att_feat = att_feat.reshape(-1, att_feat.shape[-1]) return fc_feat, att_feat, tree elif self.caption_model == 'tree_model' or self.caption_model == 'tree_model_1' \ or self.caption_model == 'tree_model_md' or self.caption_model == 'tree_model_2': return fc_feat, tree else: raise Exception("Caption model not supported: {}".format( self.caption_model))
def test_can_add_edge(): graph = Graph() babies = graph.add_vertex('babies') goats = graph.add_vertex('goats') graph.add_edge(babies, goats, 10) assert goats in graph._adjacency_list[babies] assert graph._adjacency_list[babies][goats] == 10
def teste_kruskal_mst_algorithm(self): '''Kruskal's algorithm uses Disjoint Set under the hook''' edges = [ ('a', 'b', 4), ('a', 'h', 8), ('h', 'b', 11), ('h', 'i', 7), ('h', 'g', 1), ('i', 'g', 6), ('i', 'c', 2), ('b', 'c', 8), ('c', 'f', 4), ('g', 'f', 2), ('d', 'f', 14), ('c', 'd', 7), ('d', 'e', 9), ('e', 'f', 10), ] graph = Graph() for v, u, w in edges: graph.add_edge(v, u, weight=w) tree = kruskal(graph) nro_edges = gg_edges_number(tree) cost = gg_total_weight(tree) self.assertEqual(nro_edges, 8) self.assertEqual(cost, 37) self.assertFalse(has_cycle(graph))
def test_get_neighbors(): graph = Graph() babies = graph.add_vertex('babies') goats = graph.add_vertex('goats') graph.add_edge(babies, goats, 10) neighbors = graph.get_neighbors(babies) assert goats in neighbors
def create_graph_0(dump_path, nodes_file, edges_file): print 'Creating graph ...' graph = Graph() # add the nodes nodes_list = dump_path + nodes_file nodes_data = np.loadtxt(nodes_list, skiprows=1) n_nodes, n_dim = nodes_data.shape for i in range(n_nodes): node_id = int(nodes_data[i,0]) if node_id < 0: continue x_pos = nodes_data[i,1] y_pos = nodes_data[i,2] size = nodes_data[i,3] b_fix = int(nodes_data[i,4]) rgb_color = nodes_data[i,5:8] color_energy = get_color_energy(rgb_color, size) print color_energy node = Node(node_id,\ seg_id=node_id, \ x_pos=x_pos, \ y_pos=y_pos, \ b_fix=b_fix, \ size=size, \ color_energy=color_energy, \ color=rgb_color, \ saliency=1.0, \ radius=size/2) graph.add_node(node) # add this node to the list of people nodes # graph.add_pnode(node) # graph.num_people += 1 edges_list = dump_path + edges_file edges_data = np.loadtxt(edges_list, skiprows=1) n_edges, n_dim = edges_data.shape for i in range(n_edges): src_id = edges_data[i,0] if src_id < 0: continue dst_id = edges_data[i,1] length = edges_data[i,2] src_node = graph.get_node(src_id) dst_node = graph.get_node(dst_id) assert src_node is not None assert dst_node is not None graph.add_edge(src_node, dst_node, spring_length=length) return graph
def test_add_edge(self): graph = Graph(directed=True) graph.add_vertex(data='a') graph.add_vertex(data=123) graph.add_edge(data1='a', data2=123, weight=3) self.assertEqual(graph.adjacency_list['a'].adjacent[123], 3) self.assertEqual(graph.adjacency_list[123].adjacent, {})
def test_get_vertices(): graph = Graph() vertex1 = graph.add_vertex('meat') vertex2 = graph.add_vertex('cheese') graph.add_edge(vertex1, vertex2, 11) output = graph.get_vertices() assert output == ['meat', 'cheese']
def test_add_edge_directed(self): graph = Graph(directed=True) graph.add_node(1) graph.add_node(2) graph.add_edge(1, 2) self.assertEqual(graph.nodes, {1: [(2, 0)], 2: []})
def load_from_ribs_list(graph: Graph, file_name: str): graph.clear() with open(file_name, mode='r') as file: for line in file: name = '' params = [] for index in line: if index == '{': value = '' if index.isdigit(): value += index if index == '(': name = value value = '' if index == ',': params.append(value) value = '' if index == ')': params.append(value) print(params, name) value = '' graph.add_vertex(params[1], random.randint(0, 100), random.randint(0, 100)) graph.add_vertex(params[2], random.randint(0, 100), random.randint(0, 100)) graph.add_edge(params[2], params[1], int(params[0])) graph.oriented = bool(int(params[3])) params = []
def test_check_cycles(self): G = Graph() a, b, c, d, e, f, g = Node('A'), Node('B'), Node('C'), Node('D'), Node( 'E'), Node('F'), Node('G') N = [a, b, c, d, e, f, g] for node in N: G.add_node(node) E = [ Edge(a, b), Edge(b, c), Edge(c, d), Edge(a, d), Edge(d, e), Edge(e, a), Edge(e, f), Edge(f, g), Edge(g, f), ] for edge in E: G.add_edge(edge) self.assertEqual(Graph.check_cycles(G, True), [[g, f], [e, d, c, b, a]]) self.assertEqual(Graph.check_cycles(G, False), [[g, f]])
def test_2(): graph = Graph() start = graph.add_node('first node') end = graph.add_node('edge') graph.add_edge(start , end , 0) actual = graph._adjacency_list[start][0].vertex expected = end assert actual == expected
def test_remove_vertex(self): graph = Graph() graph.add_edge(data1='a', data2=123, weight=3) self.assertEqual(graph.adjacency_list['a'].adjacent[123], 3) graph.remove_vertex(123) self.assertEqual(set(list(graph.adjacency_list.keys())), set(['a'])) self.assertEqual( set(list(graph.adjacency_list['a'].adjacent)), set([]))
def test_is_connected(self): graph = Graph() graph.add_edge(data1='a', data2=123, weight=3) graph.add_edge(data1=123, data2='c', weight=5) self.assertTrue(graph.is_connected(123, 'a')) self.assertTrue(graph.is_connected('a', 123)) self.assertFalse(graph.is_connected('a', 'b')) self.assertFalse(graph.is_connected('a', 'c'))
def test_add_edge_undirected(self): graph = Graph() graph.add_node(1) graph.add_node(2) graph.add_edge(1, 2) self.assertEqual(graph.nodes, {1: [(2, 0)], 2: [(1, 0)]}) self.assertRaises(Exception, Graph.add_edge, 0, 3)
def test_bfs(self): graph = Graph(directed=False) graph.add_edge(data1='a', data2=123, weight=3) graph.add_edge(data1='b', data2=123, weight=2) graph.add_edge(data1='c', data2=123, weight=1) graph.add_edge(data1='c', data2='a', weight=1) with self.assertRaises(TypeError) as error: t = graph.bfs(node='c')
def test_topological_sort(self): graph = Graph(directed=False) graph.add_edge(data1='a', data2=123, weight=3) graph.add_edge(data1='b', data2=123, weight=2) graph.add_edge(data1='c', data2=123, weight=1) graph.add_edge(data1='c', data2='a', weight=1) with self.assertRaises(TypeError) as error: t = graph.topological_sort()
def test_topological_sort(self): graph = Graph(directed=True) graph.add_edge(data1='a', data2=123, weight=3) graph.add_edge(data1='b', data2=123, weight=2) graph.add_edge(data1='c', data2=123, weight=1) graph.add_edge(data1='c', data2='a', weight=1) t = graph.topological_sort() self.assertEqual(t.index(123), 3)
def test_one_node_and_one_edge(): graph = Graph() start = graph.add_node('start') graph.add_edge(start, start, 10) assert graph.size() == 1 assert graph.get_neighbors(start) == [(start, 10)]
def test_get_neighbors_returns_edges_with_custom_weight(): graph = Graph() banana = graph.add_node("banana") apple = graph.add_node("apple") graph.add_edge(apple, banana, 44) neighbors = graph.get_neighbors(apple) neighbor_edge = neighbors[0] assert neighbor_edge.weight == 44
def create_graph(s_objects, p_objects): print 'Creating graph ...' graph = Graph() node_id = 0 # use this as node id as some segments might have similar id # add the imp object nodes for s_obj in s_objects: node = Node(node_id, \ seg_id=s_obj.id, \ x_pos=s_obj.pos[1], \ y_pos=s_obj.pos[0], \ b_fix=True, \ size=s_obj.size, \ color_energy=s_obj.color_energy, \ color=s_obj.color, \ saliency=s_obj.saliency, \ radius=np.sqrt(s_obj.size)/4) graph.add_node(node) node_id += 1 max_snode_id = node_id # add the people node for p_obj in p_objects: node = Node(node_id,\ seg_id=p_obj.id, \ x_pos=p_obj.pos[1], \ y_pos=p_obj.pos[0], \ b_fix=False, \ size=p_obj.size, \ color_energy=1.2*p_obj.color_energy, \ color=p_obj.color, \ saliency=1.2*p_obj.saliency, \ radius=np.sqrt(p_obj.size)/4) graph.add_node(node) # add this node to the list of people nodes graph.add_pnode(node) graph.num_people += 1 # create edges from the people node to rest of nodes for dst_id in range(max_snode_id): src_id = node_id src_node = node dst_node = graph.get_node(dst_id) assert src_node is not None assert dst_node is not None graph.add_edge(src_node, dst_node, spring_length=0.0) node_id += 1 return graph
def test_add_edge_groovy(): graph = Graph() end = graph.add_node('end') start = graph.add_node('start') graph.add_edge(start, end)
def test_get_neighbors_returns_edges_with_default_weight(): graph = Graph() banana = graph.add_node("banana") apple = graph.add_node("apple") graph.add_edge(apple, banana) neighbors = graph.get_neighbors(apple) actual = neighbors[0].weight expected = 0 assert actual == expected
def test_add_edge_other_case(): graph = Graph() end = graph.add_node('b') start = graph.add_node('a') graph.add_edge(start, end)
def test_get_neighbors(): g = Graph() apple = g.add_vertex('apple') banana = g.add_vertex('banana') cucumber = g.add_vertex('cucumber') g.add_edge(apple, banana, 4) g.add_edge(apple, cucumber, 5) neighbors = g.get_neighbors(apple) assert neighbors == [(banana, 4), (cucumber, 5)]
def test_add_edge_missing_vertex(): g = Graph() h = Graph() apple = g.add_vertex('apple') banana = h.add_vertex('banana') g.add_edge(apple, banana, 4) for v in g.get_vertices(): if v.value == 'apple': assert v.adjacencies == []
def test_add_edge_end(): graph = Graph() end = Vertix('b') start = graph.add_node('a') with pytest.raises(KeyError): graph.add_edge(start, end)
def test_get_neighbors_returns_edges(): graph = Graph() banana = graph.add_node("banana") apple = graph.add_node("apple") graph.add_edge(apple, banana) neighbors = graph.get_neighbors(apple) assert len(neighbors) == 1 neighbor = neighbors[0] assert isinstance(neighbor, Edge) assert neighbor.vertex.value == 'banana'
def test_get_neighbors(): graph = Graph() a = graph.add_node('a') b = graph.add_node('b') c = graph.add_node('c') graph.add_edge(a, b) graph.add_edge(a, c, 2) actual = graph.get_neighbors(a) expected = [{'Value': 'b', 'Weight': 1}, {'Value': 'c', 'Weight': 2}] assert actual == expected
def test_add_weightless_edge(): g = Graph() apple = g.add_vertex('apple') banana = g.add_vertex('banana') g.add_edge(apple, banana) for v in g.get_vertices(): if v.value == 'apple': assert (banana, 0) in v.adjacencies if v.value == 'banana': assert (apple, 0) in v.adjacencies
def test_remove_vertex(self): g = Graph() vertex1 = g.add_vertex('v1') vertex2 = g.add_vertex('v2') g.add_vertex('v3') edge1 = g.add_edge('v1', 'v2') edge2 = g.add_edge('v1', 'v3') edge3 = g.add_edge('v2', 'v3') g.remove_vertex('v3') self.assertEqual(2, len(g.vertices)) self.assertEqual(1, len(g.edges)) self.assertTrue('v3' not in g.vertices) self.assertEqual(1, len(vertex1.neighbors)) self.assertEqual(1, len(vertex2.neighbors))
def test_get_successor_predecessor(self): g = Graph() v1 = g.add_vertex('v1') v2 = g.add_vertex('v2') v3 = g.add_vertex('v3') e1 = g.add_edge(v1, v2) e2 = g.add_edge(v1, v3) e3 = g.add_edge(v2, v3) self.assertEqual(2, len(v1.get_successors())) self.assertEqual(1, len(v2.get_successors())) self.assertEqual(0, len(v3.get_successors())) self.assertEqual(0, len(v1.get_predecessors())) self.assertEqual(1, len(v2.get_predecessors())) self.assertEqual(2, len(v3.get_predecessors()))
def construct_triangle_network(self): """Constructs a triangle, clearly not bipartite""" network = Graph() n1 = Node(1) n2 = Node(2) n3 = Node(3) network.add_node(n1) network.add_node(n2) network.add_node(n3) network.add_edge(UndirectedEdge(n1, n2)) network.add_edge(UndirectedEdge(n2, n3)) network.add_edge(UndirectedEdge(n3, n1)) return network
def get_MST_Kruskal(graph): graph.sort_edges() sorted_edges = graph.edges mst = Graph() # koloruje graf graph.set_nodes_id() for edge in sorted_edges: if edge.has_different_ids(): # jeżeli tak zamieniamy wszystkie id takie jak wezła koncowego na takie jak wezła poczatkowego w grafi graph.change_all_ids(edge.end_node.id, edge.start_node.id) mst.add_edge(edge) return mst
def test_add_edge(self): g = Graph() g.add_vertex('v1') g.add_vertex('v2') g.add_vertex('v3') g.add_vertex('v4') edge = g.add_edge('v1', 'v2') self.assertEqual(1, len(g.edges)) self.assertEqual(1, len(g.get_vertex('v1').neighbors)) self.assertEqual(1, len(g.get_vertex('v2').neighbors)) self.assertTrue(g.get_vertex('v1') in edge.get_vertices()) self.assertTrue(g.get_vertex('v2') in edge.get_vertices()) edge = g.add_edge('v3', 'v4', label='foo', value=10) self.assertEqual('foo', edge.label) self.assertEqual(10, edge.value)
def construct_bp_network(self): network = Graph() n1 = Node(1) n2 = Node(2) n3 = Node(3) n4 = Node(4) n5 = Node(5) n6 = Node(6) # Add nodes to graph network.add_node(n1) network.add_node(n2) network.add_node(n3) network.add_node(n4) network.add_node(n5) network.add_node(n6) # Add edges in zig-zag pattern network.add_edge(UndirectedEdge(n1, n2)) network.add_edge(UndirectedEdge(n2, n3)) network.add_edge(UndirectedEdge(n3, n4)) network.add_edge(UndirectedEdge(n4, n5)) network.add_edge(UndirectedEdge(n5, n6)) return network
def get_MST_Prim(graph): mst = Graph() # node poczatkowy node = graph.nodes[0] # znajduje wszystkie krawedzie zawiedające node edges = graph.get_edges_with_nodes([node]) edges.sort(key=lambda e: e.weight) # dodaje najlzejsza krawędź do mst edge_to_add = edges[0] mst.add_edge(edge_to_add) #zaznaczam nody jako zużyte graph.set_node_id(edge_to_add.start_node, 1) graph.set_node_id(edge_to_add.end_node, 1) while len(mst.edges) < len(graph.nodes)-1: # znajdujemy zużyte nody (dla uproszczenia z mst) nodes = mst.nodes # zanajdujemy krawedzie z zuzytymi wierzchołkami edges = graph.get_edges_with_nodes(nodes) # usuwam krawedzie z dwoma zużytymi nodami edges = get_edges_with_one_used_node(edges) # znajduje najlżejszą krawedz edges.sort(key=lambda e: e.weight) edge_to_add = edges[0] mst.add_edge(edge_to_add) # zaznaczam nody jako zużyte graph.set_node_id(edge_to_add.start_node, 1) graph.set_node_id(edge_to_add.end_node, 1) return mst
def test_remove_edge(self): g = Graph() vertex1 = g.add_vertex('v1') vertex2 = g.add_vertex('v2') vertex3 = g.add_vertex('v3') edge1 = g.add_edge(vertex1, vertex2) edge2 = g.add_edge(vertex2, vertex3) g.remove_edge(edge1) self.assertEqual(1, len(g.edges)) self.assertTrue(edge1 not in g.edges) self.assertTrue(vertex2 not in vertex1.neighbors) g.remove_edge_between('v2', vertex3) self.assertEqual(0, len(g.edges)) self.assertTrue(edge2 not in g.edges) self.assertTrue(vertex3 not in vertex2.neighbors)
from algorithms.kurskal import get_MST_Kruskal from algorithms.prim import get_MST_Prim from graph.egde import Edge from graph.graph import Graph from graph.node import Node __author__ = 'Jakub' if __name__ == '__main__': graph = Graph() graph.add_edge(Edge(Node("1"), Node("2"), 1)) graph.add_edge(Edge(Node("1"), Node("3"), 2)) graph.add_edge(Edge(Node("4"), Node("1"), 2)) graph.add_edge(Edge(Node("1"), Node("5"), 6)) graph.add_edge(Edge(Node("2"), Node("4"), 4)) graph.add_edge(Edge(Node("2"), Node("5"), 5)) graph.add_edge(Edge(Node("3"), Node("4"), 3)) graph.add_edge(Edge(Node("4"), Node("5"), 3)) # graph.add_edge(Edge(Node("a"), Node("b"), 4)) # graph.add_edge(Edge(Node("a"), Node("e"), 1)) # graph.add_edge(Edge(Node("a"), Node("f"), 2)) # # graph.add_edge(Edge(Node("b"), Node("c"), 2)) # graph.add_edge(Edge(Node("b"), Node("e"), 2))
class TestGraphQuery(unittest.TestCase): """ Tests for graph queries. Tests for graph queries. Tests include testsing longest edge, shortest edge, average edge distance, biggest vertex, smallest vertex, average vertex size, continents info, hub cities, and map url. """ def setUp(self): self.graph = Graph() self.graph.load("../json/test_data.json") def test_longest_edge(self): longest_edge = sorted(self.graph.calculate_longest_edge(), key=lambda x: x.departure.code) self.assertEqual(longest_edge[0].departure.code, "LIM") self.assertEqual(longest_edge[1].departure.code, "MEX") self.assertEqual(longest_edge[0].distance, 24530) def test_shortest_edge(self): shortest_edge = sorted(self.graph.calculate_shortest_edge(), key=lambda x: x.departure.code) self.assertEqual(shortest_edge[1].departure.code, "SCL") self.assertEqual(shortest_edge[0].departure.code, "LIM") self.assertEqual(shortest_edge[0].distance, 2453) def test_average_distance(self): average_distance = self. graph.calculate_average_distance() self.assertEqual(int(average_distance), 10594) def test_biggest_vertex(self): biggest_vertex = self.graph.calculate_biggest_vertex() self.assertEqual(biggest_vertex.code, "MEX") def test_smallest_vertex(self): smallest_vertex =self.graph.calculate_smallest_vertex() self.assertEqual(smallest_vertex.code, "SCL") def test_average_size(self): average_size = self. graph.calculate_average_vertex_size() self.assertEqual(int(average_size), 12816666) def test_continents_info(self): continents_dict = self.graph.calculate_continents_info() self.assertTrue("South America" in continents_dict.keys()) self.assertTrue("North America" in continents_dict.keys()) cities = [] for value in continents_dict.values(): for city in value: cities.append(city.code) self.assertTrue("MEX" in cities) self.assertTrue("SCL" in cities) self.assertTrue("LIM" in cities) def test_hub_cities(self): hub_cities = self.graph.calculate_hub_cities() hub_cities = [hub_cities[0].code, hub_cities[1].code, hub_cities[2].code] self.assertTrue("MEX" in hub_cities) self.assertTrue("SCL" in hub_cities) self.assertTrue("MEX" in hub_cities) def test_map_url(self): url = self.graph.generate_map_url() self.assertTrue("MEX-SCL" in url) self.assertTrue("LIM-MEX" in url) self.assertTrue("SCL-LIM" in url) def test_add_vertex(self): self.assertTrue(self.graph.add_vertex(city)) self.assertTrue("CMI" in self.graph.vertices.keys()) self.assertEqual(self.graph.vertices["CMI"].name, "Champaign") def test_add_edge(self): self.assertTrue(self.graph.add_vertex(city)) self.assertFalse(self.graph.add_edge("CMI", "PAR", 30000)) self.assertTrue(self.graph.add_edge("CMI", "MEX", 30000)) edges = [] for edge in self.graph.edges.values(): edges.append(edge.departure.code + " -> " + edge.destination.code + ", " + str(edge.distance)) edges.sort() self.assertEqual(edges, ['CMI -> MEX, 30000', 'LIM -> MEX, 24530', 'LIM -> SCL, 2453', 'MEX -> LIM, 24530', 'MEX -> SCL, 4800', 'SCL -> LIM, 2453', 'SCL -> MEX, 4800']) def test_remove_edge(self): self.assertFalse(self.graph.remove_edge("CMI", "PAR")) self.assertTrue(self.graph.add_vertex(city)) self.assertTrue(self.graph.add_edge("CMI", "MEX", 30000)) self.assertTrue(self.graph.remove_edge("CMI", "MEX")) edges = [] for edge in self.graph.edges.values(): edges.append(edge.departure.code + " -> " + edge.destination.code + ", " + str(edge.distance)) edges.sort() self.assertEqual(edges, ['LIM -> MEX, 24530', 'LIM -> SCL, 2453', 'MEX -> LIM, 24530', 'MEX -> SCL, 4800', 'SCL -> LIM, 2453', 'SCL -> MEX, 4800']) def test_remove_vertex(self): self.assertFalse(self.graph.remove_vertex("PAR")) self.assertTrue(self.graph.add_vertex(city)) self.assertTrue(self.graph.add_edge("CMI", "MEX", 30000)) self.assertTrue(self.graph.remove_vertex("CMI")) self.assertFalse("CMI" in self.graph.vertices.keys()) edges = [] for edge in self.graph.edges.values(): edges.append(edge.departure.code + " -> " + edge.destination.code + ", " + str(edge.distance)) edges.sort() self.assertEqual(edges, ['LIM -> MEX, 24530', 'LIM -> SCL, 2453', 'MEX -> LIM, 24530', 'MEX -> SCL, 4800', 'SCL -> LIM, 2453', 'SCL -> MEX, 4800']) def test_save_to_disk(self): test_string = '{"metros": [{"code": "LIM", "continent": "South America", "coordinates": {"S": 12, "W": 77}, "country": "PE", "name": "Lima", "population": 9050000, "region": 1, "timezone": -5}, {"code": "MEX", "continent": "North America", "coordinates": {"N": 19, "W": 99}, "country": "MX", "name": "Mexico City", "population": 23400000, "region": 1, "timezone": -6}, {"code": "SCL", "continent": "South America", "coordinates": {"S": 33, "W": 71}, "country": "CL", "name": "Santiago", "population": 6000000, "region": 1, "timezone": -4}], "routes": [{"distance": 24530, "ports": ["LIM", "MEX"]}, {"distance": 2453, "ports": ["LIM", "SCL"]}, {"distance": 24530, "ports": ["MEX", "LIM"]}, {"distance": 4800, "ports": ["MEX", "SCL"]}, {"distance": 2453, "ports": ["SCL", "LIM"]}, {"distance": 4800, "ports": ["SCL", "MEX"]}]}' json_string = json.dumps(self.graph.convert_to_json(), sort_keys=True) self.assertEqual(json_string, test_string) def test_route_info(self): route = ['MEX', 'SCL', 'LIM'] self.assertTrue(self.graph.is_valid_route(route)) cost, time = self.graph.calculate_route_info(route) self.assertEqual(cost, 2415.90) self.assertEqual(time, 12.57) self.graph.remove_edge("MEX", "SCL") self.assertFalse(self.graph.is_valid_route(route)) def test_shortest_path(self): shortest_path = ['MEX', 'SCL', 'LIM'] route = self.graph.calculate_shortest_path(['MEX', 'LIM']) self.assertEqual(route, shortest_path) self.assertTrue(self.graph.add_vertex(city)) route = self.graph.calculate_shortest_path(['MEX', 'CMI']) self.assertEqual(route, None)