def test_parcel_allocations_doctest() -> None: """Test the doctest provided for Fleet.parcel_allocations""" f = Fleet() t1 = Truck(1423, 10, 'Toronto') p1 = Parcel(27, 5, 'Toronto', 'Hamilton') p2 = Parcel(12, 5, 'Toronto', 'Hamilton') assert t1.pack(p1) is True assert t1.pack(p2) is True t2 = Truck(1333, 10, 'Toronto') p3 = Parcel(28, 5, 'Toronto', 'Hamilton') assert t2.pack(p3) is True f.add_truck(t1) f.add_truck(t2) assert f.parcel_allocations() == {1423: [27, 12], 1333: [28]}
def test_greedy_scheduler_example() -> None: """Test GreedyScheduler on the example provided.""" p17 = Parcel(17, 25, 'York', 'Toronto') p21 = Parcel(21, 10, 'York', 'London') p13 = Parcel(13, 8, 'York', 'London') p42 = Parcel(42, 20, 'York', 'Toronto') p25 = Parcel(25, 15, 'York', 'Toronto') p61 = Parcel(61, 15, 'York', 'Hamilton') p76 = Parcel(76, 20, 'York', 'London') t1 = Truck(1, 40, 'York') t2 = Truck(2, 40, 'York') t3 = Truck(3, 25, 'York') f = Fleet() f.add_truck(t1) f.add_truck(t2) f.add_truck(t3) # We've left parcel_file, truck_file, and map_file empty in the config # dictionary below because you should *not* use these in your # GreedyScheduler. It is not responsible for reading data from these files. config = { 'depot_location': 'York', 'parcel_file': '', 'truck_file': '', 'map_file': '', 'algorithm': 'greedy', 'parcel_priority': 'destination', 'parcel_order': 'non-increasing', 'truck_order': 'non-increasing', 'verbose': 'false' } scheduler = GreedyScheduler(config) unscheduled = scheduler.schedule([p17, p21, p13, p42, p25, p61, p76], [t1, t2, t3]) assert unscheduled == [p76] truck_parcels = f.parcel_allocations() assert truck_parcels[1] == [17, 61] assert truck_parcels[2] == [42, 25] assert truck_parcels[3] == [21, 13]
def test_empty_fleet_allocations() -> None: """Test that an empty dictionary is returned, for an empty fleet of parcel allocations.""" f = Fleet() assert f.parcel_allocations() == {}