def test_is_delivered(): item = shp.Item(code=43654) shipment = shp.Bin('in', contents=[item], destination='Toronto', number=8) truck = shp.Truck(destination='Toronto') truck.contents = [shipment] truck.deliver() assert truck.contents == [] assert truck.is_delivered() is True item, item2 = shp.Item(code=45), shp.Item(code=90) shipment = shp.Bin('in', contents=[item, item2], destination='Toronto', number=8) truck = shp.Truck(destination='Toronto') truck.contents = [shipment] truck.deliver() assert truck.contents == [] assert truck.is_delivered() is True shp.Item.all_codes = []
def test_send_bin(): shipment = shp.Bin('in', contents=[shp.Item()], destination='Toronto', number=87) truck = shp.Truck(destination='Toronto') shipment.send_bin(truck) assert truck.contents[0] == shipment shipment = shp.Bin('in', contents=[shp.Item(code=14)], destination='random', number=87) truck = shp.Truck(destination='random') shipment.send_bin(truck) assert truck.contents[0] == shipment shipment = shp.Bin('in', contents=[shp.Item(code=1331)], destination='random', number=87) truck = shp.Truck(destination='Toronto') try: shipment.send_bin(truck) assert False except shp.ShipmentError: assert True shp.Item.all_codes = []
def test_get_item(): item = shp.Item(code=43654) shipment = shp.Bin('in', contents=[item], destination='random', number=8) assert shipment.get_item(item.code) == item item1, item2, item3 = shp.Item(code=57), shp.Item(code=89), shp.Item( code=84) shipment = shp.Bin('in', contents=[item1, item2, item3], destination='random', number=8) assert shipment.get_item(57) == item1 assert shipment.get_item(780) == -1 shp.Item.all_codes = []
def test_bin_remove(): item = shp.Item(code=43654) shipment = shp.Bin('in', contents=[item], destination='random', number=8) shipment.remove(item) assert shipment.contents == [] item1, item2, item3 = shp.Item(code=57), shp.Item(code=900), shp.Item( code=84) shipment = shp.Bin('in', contents=[item1, item2, item3], destination='random', number=8) shipment.remove(item2) assert shipment.contents == [item1, item3] shp.Item.all_codes = []
def test_item_count(): shipment = shp.Bin('in', contents=[ shp.Item(code=1331), shp.Item(code=12345), shp.Item(code=678) ], destination='random', number=8) assert shipment.item_count() == 3 shipment = shp.Bin('out', contents=[shp.Item()], destination='someplace', number=8) assert shipment.item_count() == 1 shp.Item.all_codes = []
def test_load_bin(): item, item2 = shp.Item(code=45), shp.Item(code=90) shipment = shp.Bin('in', contents=[item, item2], destination='Toronto', number=8) truck = shp.Truck(destination='Toronto') truck.load_bin(shipment) assert truck.contents == [shipment] item = shp.Item() shipment = shp.Bin('in', contents=[item], destination='Calgary', number=8) try: truck.load_bin(shipment) assert False except shp.ShipmentError: assert True
def test_add(): shipment = shp.Bin('out', contents=[], destination='someplace', number=8) item = shp.Item() shipment.add(item) assert shipment.contents == [item] shipment = shp.Bin('in', contents=[ shp.Item(code=1331), shp.Item(code=12345), shp.Item(code=678) ], destination='random', number=8) item = shp.Item(code=43654) shipment.add(item) assert shipment.contents[-1] == item shp.Item.all_codes = []