예제 #1
0
def test_paths_available():
    airports, schedule = initialize_schedule("../airports.txt",
                                             "../flights.txt")
    # airports, schedule = init_schedule_with_date("../airports.txt", "../fli.txt")

    start = airports[0]
    end = airports[1]

    shift = datetime.strptime("29-12-2018", "%d-%m-%Y") - datetime.strptime(
        "1-1-2018", "%d-%m-%Y")
    start_time = timedelta(hours=12, minutes=00) + shift
    total_time = timedelta(hours=8)

    paths = list_routes(schedule, start, end, start_time, total_time)

    list_costs = list()
    if len(paths) != 0:
        for path in paths:
            cost = timedelta(0)
            arrive_time = start_time
            for f in path:
                curr_cost = l(f) - arrive_time + a(f) - l(f)
                cost = curr_cost + cost
                arrive_time = a(f)
            if cost > total_time:
                print("Test test_paths_available failed")
                return
            list_costs.append(cost)
        if len(paths) == 5 and len(list_costs) == 5 and all(
                i <= total_time for i in list_costs):
            print("Test test_paths_available passed")
        else:
            print("Test test_paths_available failed")
    else:
        print("Test test_paths_available failed")
def test_select_flight_result_is_the_expected_one_B_lessequal_zero_2():
    airports, flights = initialize_schedule("../airports.txt",
                                            "../flights_light.txt")
    result, money, total_cost = select_flight(airports, flights, 0)
    if result is None\
            and money is None\
            and total_cost <= 0:
        print("test passed")
    else:
        print("test failed")
def test_select_flight_result_is_the_expected_one():
    airports, flights = initialize_schedule("../airports.txt",
                                            "../flights_light.txt")
    result, money, total_cost = select_flight(airports, flights, 600)
    if str(result[0]) == "BCN FCO 2018/12/29 18:25:00 20:15:00 517"\
            and str(result[1]) == "BCN FCO 2018/12/29 16:40:00 18:25:00 625"\
            and str(result[2]) == "LHR FCO 2018/12/29 16:10:00 19:45:00 651"\
            and total_cost == 550:
        print("test passed")
    else:
        print("test failed")
예제 #4
0
def test_no_flight_available():
    airports, schedule = initialize_schedule("../airports.txt",
                                             "../flights.txt")
    #airports, schedule = init_schedule_with_date("../airports.txt", "../fli.txt")

    start = airports[0]
    end = airports[1]

    shift = datetime.strptime("29-12-2018", "%d-%m-%Y") - datetime.strptime(
        "1-1-2018", "%d-%m-%Y")
    start_time = timedelta(hours=6, minutes=00) + shift
    total_time = timedelta(hours=1)

    paths = list_routes(schedule, start, end, start_time, total_time)
    if len(paths) != 0:
        print("Test test_no_flight_available failed")
    else:
        print("Test test_no_flight_available passed")
def test_path_available_check_it_is_the_shortest():
    airports, schedule = initialize_schedule("../airports.txt", "../flights.txt")
    #airports, schedule = init_schedule_with_date("../airports.txt", "../fli.txt")

    start = airports[0]
    end = airports[1]

    shift = datetime.strptime(
        "29-12-2018", "%d-%m-%Y") - datetime.strptime(
        "1-1-2018","%d-%m-%Y")

    start_time = timedelta(hours=12, minutes=00) + shift

    path = find_route(schedule=schedule,
                      start=start,
                      dest=end,
                      t=start_time)

    cost = None
    if len(path) != 0:
        cost = timedelta(0)
        arrive_time = start_time
        for f in path:
            curr_cost = l(f) - arrive_time + a(f) - l(f)
            cost = curr_cost + cost
            arrive_time = a(f)
    else:
        print("Test test_path_available_check_it_is_the_shortest failed")

    # Chiamando la list_routes() dell'esercizio 1 richiedendo come costo totale
    # il costo dello shortest path, la funzione deve restituire solo e soltando quel volo.
    paths = list_routes(schedule=schedule,
                        source=start,
                        dest=end,
                        t=start_time,
                        T=cost)
    if len(paths[0]) != 1:
        print("Test test_path_available_check_it_is_the_shortest failed")
    else:
        if str(paths[0][0]) == str(path[0]):
            print("Test test_path_available_check_it_is_the_shortest passed")
        else:
            print("Test test_path_available_check_it_is_the_shortest failed")
def test_no_flight_available():
    airports, schedule = initialize_schedule("../airports.txt", "../flights.txt")
    #airports, schedule = init_schedule_with_date("../airports.txt", "../fli.txt")

    shift = datetime.strptime(
        "29-12-2018", "%d-%m-%Y") - datetime.strptime(
        "1-1-2018", "%d-%m-%Y")
    start = airports[8]  # OSL
    end = airports[7]    # SVO

    start_time = timedelta(hours=8, minutes=00) + shift

    paths = find_route(schedule=schedule,
                       start=start,
                       dest=end,
                       t=start_time)
    if len(paths) != 0:
        print("Test test_no_flight_available failed")
    else:
        print("Test test_no_flight_available passed")