def test_flights(): graph = Graph() metroville = graph.add_node("Metroville") pandora = graph.add_node("Pandora") arendelle = graph.add_node("Arendelle") graph.add_edge(pandora, arendelle, 150) graph.add_edge(arendelle, pandora, 150) graph.add_edge(pandora, metroville, 82) graph.add_edge(metroville, pandora, 82) graph.add_edge(metroville, arendelle, 99) graph.add_edge(arendelle, metroville, 99) assert get_edge(graph, ["Metroville","Pandora"]) == (False,0) assert get_edge(graph, ["Metroville","arendelle"]) == (False,0) assert get_edge(graph, ["arendelle","Pandora"]) == (False,0)
def test_double_flight(): g = Graph() aberdeen = g.add_vertex('Aberdeen') nairn = g.add_vertex('Nairn') perth = g.add_vertex('Perth') macduff = g.add_vertex('MacDuff') banff = g.add_vertex('Banff') glasgow = g.add_vertex('Glasgow') portree = g.add_vertex('Portree') g.add_edge(aberdeen, nairn, 70) g.add_edge(nairn, aberdeen, 70) g.add_edge(aberdeen, perth, 50) g.add_edge(perth, aberdeen, 50) g.add_edge(aberdeen, macduff, 35) g.add_edge(macduff, aberdeen, 35) g.add_edge(perth, macduff, 45) g.add_edge(macduff, perth, 45) g.add_edge(macduff, banff, 15) g.add_edge(banff, macduff, 15) g.add_edge(macduff, glasgow, 40) g.add_edge(glasgow, macduff, 40) assert get_edge(g, [aberdeen, macduff, glasgow]) == True, f'${75}'
def test_for_false_island(): g = Graph() aberdeen = g.add_vertex('Aberdeen') nairn = g.add_vertex('Nairn') perth = g.add_vertex('Perth') macduff = g.add_vertex('MacDuff') banff = g.add_vertex('Banff') glasgow = g.add_vertex('Glasgow') portree = g.add_vertex('Portree') g.add_edge(aberdeen, nairn, 70) g.add_edge(nairn, aberdeen, 70) g.add_edge(aberdeen, perth, 50) g.add_edge(perth, aberdeen, 50) g.add_edge(aberdeen, macduff, 35) g.add_edge(macduff, aberdeen, 35) g.add_edge(perth, macduff, 45) g.add_edge(macduff, perth, 45) g.add_edge(macduff, banff, 15) g.add_edge(banff, macduff, 15) g.add_edge(macduff, glasgow, 40) g.add_edge(glasgow, macduff, 40) assert get_edge(g, [glasgow, portree]) == False, '$0'
def test_two_cities(): graph = Graph() city_1 = graph.add_node('Seattle') city_2 = graph.add_node('Portland') city_3 = graph.add_node('San') graph.add_edge(city_1, city_2, 150) graph.add_edge(city_2, city_3, 200) assert get_edge(graph, [city_1, city_2]) == 'True, $150'
def test_2_way(): graph = Graph() city_1 = graph.add_node('Seattle') city_2 = graph.add_node('Portland') city_3 = graph.add_node('San') city_4 = graph.add_node('LA') graph.add_edge(city_1, city_2, 150) graph.add_edge(city_1, city_3, 200) graph.add_edge(city_2, city_1, 150) assert get_edge(graph, [city_1, city_2, city_1]) == 'True, $300'
def test_circle_false_2(): graph = Graph() city_1 = graph.add_node('Seattle') city_2 = graph.add_node('Portland') city_3 = graph.add_node('San') city_4 = graph.add_node('LA') graph.add_edge(city_1, city_2, 150) graph.add_edge(city_1, city_3, 200) graph.add_edge(city_3, city_4, 300) assert get_edge(graph, [city_1, city_3, city_4]) == 'True, $500'
def test_list_of_cities_is_empty(): graph = Graph() city_1 = graph.add_node('Seattle') city_2 = graph.add_node('Portland') graph.add_edge(city_1, city_2, 150) assert get_edge(graph, []) == 'False, $0'
def test_one_city(): graph = Graph() city_1 = graph.add_node('Seattle') city_2 = graph.add_node('Portland') graph.add_edge(city_1, city_2, 150) assert get_edge(graph, [city_1]) == 'False, $0'
def test_two_direct_cities(my_graph): graph = my_graph assert get_edge(graph, ['Metroville', 'Pandora']) == (True, '$82')
def test_city_not_in_graph(my_graph): graph = my_graph assert get_edge(graph, ['Metroville', 'Pandora', 'Kazan']) == (False, '$0')
def test_three_non_direct_cities(my_graph): graph = my_graph assert get_edge(graph, ['Narnia', 'Arendelle', 'Naboo']) == (False, '$0')
def test_two_non_direct_cities(my_graph): graph = my_graph assert get_edge(graph, ['Naboo', 'Pandora']) == (False, '$0')
def test_three_direct_cities(my_graph): graph = my_graph assert get_edge(graph, ['Arendelle', 'Monstropolis', 'Naboo']) == (True, '$115')
path = 'blur_test.py' method_name = 'gaussian_blur' #path = 'blur_two_stage.py' #method_name = 'two_stage_blur' source = open(path, 'rt').read() node = ast.parse(source) node = transformers.ParentNodeTransformer().visit(node) visitor = ast_node_visitor.DependencyVisitor() visitor.visit(node) local_types = get_type.get_types(os.getcwd(), source) (lo_Ls, hi_Ls, var_Ls, chosen_radius_Ls, all_z3_vars) = get_edge.get_edge(source, local_types, method_name) #visualize.display_output_and_click(local_types['test_result'], node, visitor, chosen_radius_Ls, all_z3_vars) radius_r = chosen_radius_Ls[-1][0] radius_c = chosen_radius_Ls[-1][1] return_nodes = [ tnode for tnode in visitor.def_info[method_name]['return'] if tnode.id in visitor.def_info[method_name]['array'] ] for return_node in return_nodes: write_nodes = visitor.def_info[method_name]['write'][return_node.id]