Esempio n. 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")
Esempio n. 2
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")