def testGetCheapestShipmentsNotFound(self):
     orders = {'apple': 1}
     warehouses = [{'name': 'owd', 'inventory': {'apple': 0}}]
     inventoryAllocator = InventoryAllocator()
     cheapestShipment = \
         inventoryAllocator.getCheapestShipments(orders, warehouses)
     self.assertEqual(cheapestShipment, [])
 def test_happy_case(self):
     #exact inventory match
     order = {'apple': 1}
     inventory = [{'name': 'owd', 'inventory': {'apple': 1}}]
     output = [{'owd': {'apple': 1}}]
     inventory_allocation = InventoryAllocator(order, inventory)
     self.assertEqual(inventory_allocation.shipment_allocation(), output)
Example #3
0
 def test_multiple_items_multiple_warehouses_permutation2(self):
     order = {"apple": 5, "banana": 5, "orange": 3}
     warehouses = self.select_warehouses([0, 1, 2, 3])
     expected = [
         {
             'w2': {
                 'apple': 1,
                 'banana': 1,
                 'orange': 1
             }
         },
         {
             'w3': {
                 'apple': 4,
                 'orange': 2
             }
         },
         {
             'w4': {
                 'banana': 4
             }
         },
     ]
     inventory_allocator = InventoryAllocator(order, warehouses)
     shipment = inventory_allocator.allocate_inventory()
     self.assertCountEqual(
         shipment, expected,
         "Multiple items in the order, fufilled by multiple warehouses")
 def testGetCheapestShipmentsOneOrderMultipleShipments(self):
     orders = {'apple': 10}
     warehouses = [{
         'name': 'owd',
         'inventory': {
             'apple': 5
         }
     }, {
         'name': 'dm',
         'inventory': {
             'apple': 5
         }
     }]
     inventoryAllocator = InventoryAllocator()
     cheapestShipment = \
         inventoryAllocator.getCheapestShipments(orders, warehouses)
     self.assertEqual(cheapestShipment, [{
         'dm': {
             'apple': 5
         }
     }, {
         'owd': {
             'apple': 5
         }
     }])
Example #5
0
def test_multiple_match1():
    allocator = InventoryAllocator()
    actual_result = allocator.cheapest_shipment_calculator({'apple': 10}, [{'name': 'owd', 'inventory': {'apple': 5}},
                                                                           {'name': 'dm', 'inventory': {'apple': 5}}])
    expected_result = [{'owd': {'apple': 5}},
                       {'dm': {'apple': 5}}]
    assert actual_result == expected_result
Example #6
0
 def test_order_with_zero_number(self):
     order = {"apple": 0, "banana": 0}
     warehouses = self.select_warehouses([0, 1, 2, 3])
     expected = []
     inventory_allocator = InventoryAllocator(order, warehouses)
     shipment = inventory_allocator.allocate_inventory()
     self.assertEqual(shipment, expected, "Order with zero item number")
 def test_empty_order(self):
     #order is empty
     order = {}
     inventory = [{'name': 'owd', 'inventory': {'apple': 1}}]
     output = []
     inventory_allocation = InventoryAllocator(order, inventory)
     self.assertEqual(inventory_allocation.shipment_allocation(), output)
Example #8
0
 def test_no_order_exist_inventory(self):
     order = {}
     warehouses = self.select_warehouses([1])
     expected = []
     inventory_allocator = InventoryAllocator(order, warehouses)
     shipment = inventory_allocator.allocate_inventory()
     self.assertEqual(shipment, expected, "No order, but exist inventory")
Example #9
0
 def test_order_multiple_items(self):
     order = {'apple': 10, 'banana': 10, 'orange': 10}
     inventory = [{
         'name': 'owd',
         'inventory': {
             'apple': 10,
             'banana': 5,
             'orange': 15
         }
     }, {
         'name': 'dm',
         'inventory': {
             'apple': 5,
             'banana': 20,
             'orange': 5
         }
     }]
     order_output = [{
         'owd': {
             'apple': 10,
             'banana': 5,
             'orange': 10
         }
     }, {
         'dm': {
             'banana': 5
         }
     }]
     inventory_allocator = InventoryAllocator(order, inventory)
     self.assertEqual(inventory_allocator.allocate_inventory(),
                      order_output)
 def test_not_enough_inventory(self):
     # test for not enough inventory
     order = {'apple': 1}
     inventory = [{'name': 'owd', 'inventory': {'apple': 0}}]
     output = []
     inventory_allocator = InventoryAllocator(order, inventory)
     self.assertEqual(inventory_allocator.shipment(), output)
 def test_not_enough_inventory(self):
     #not enough inventory --> no allocations!
     order = {'apple': 1}
     inventory = [{'name': 'owd', 'inventory': {'apple': 0}}]
     output = []
     inventory_allocation = InventoryAllocator(order, inventory)
     self.assertEqual(inventory_allocation.shipment_allocation(), output)
 def test_no_order_no_inventory(self):
     # test for no order placed and no inventory details
     order = {}
     inventory = []
     output = []
     inventory_allocator = InventoryAllocator(order, inventory)
     self.assertEqual(inventory_allocator.shipment(), output)
 def test_no_item(self):
     # test for item not found in inventory
     order = {'kiwi': 1}
     inventory = [{'name': 'owd', 'inventory': {'apple': 1}}]
     output = []
     inventory_allocator = InventoryAllocator(order, inventory)
     self.assertEqual(inventory_allocator.shipment(), output)
Example #14
0
    def test_not_enough_inventory_for_single_item(self):
        # no warehouses
        self.assertEqual([],
                         InventoryAllocator().allocate_order({'item1': 10},
                                                             []))

        # warehouse object is null
        self.assertEqual([],
                         InventoryAllocator().allocate_order({'item1': 10},
                                                             [Warehouse()]))

        # warehouse exist, but does not have item
        self.assertEqual([],
                         InventoryAllocator().allocate_order(
                             {'item1': 10}, [Warehouse('wh1', {'item2': 10})]))

        # not enough quantity in a single warehouse
        self.assertEqual([],
                         InventoryAllocator().allocate_order(
                             {'item1': 10}, [Warehouse('wh1', {'item1': 5})]))

        # not enough quantity in a multiple warehouses
        self.assertEqual([],
                         InventoryAllocator().allocate_order({'item1': 10}, [
                             Warehouse('wh1', {'item1': 5}),
                             Warehouse('wh2', {'item1': 2}),
                             Warehouse('wh3', {'item1': 2})
                         ]))
 def test_no_inventory(self):
     # test for no inventory details
     order = {'apple': 1}
     inventory = []
     output = []
     inventory_allocator = InventoryAllocator(order, inventory)
     self.assertEqual(inventory_allocator.shipment(), output)
 def testEmptyWarehouseOneOrderWithLeftovers(self):
     orders = {'orange': 20}
     warehouses = [{
         'name': 'owd',
         'inventory': {
             'apple': 5,
             'orange': 10
         }
     }, {
         'name': 'dm',
         'inventory': {
             'banana': 5,
             'orange': 10
         }
     }]
     furthest = 1
     cheapestShipment = []
     inventoryAllocator = InventoryAllocator()
     leftovers, cheapestShipment = \
         inventoryAllocator.emptyWarehouse(orders,
                                           warehouses,
                                           furthest,
                                           cheapestShipment)
     self.assertEqual(leftovers, {'orange': 10})
     self.assertEqual(cheapestShipment, [{'dm': {'orange': 10}}])
 def test_no_order(self):
     # test for no order places
     order = {}
     inventory = [{'name': 'owd', 'inventory': {'apple': 1}}]
     output = []
     inventory_allocator = InventoryAllocator(order, inventory)
     self.assertEqual(inventory_allocator.shipment(), output)
 def test_all_empty(self):
     #empty order and empty inventory
     order = {}
     inventory = []
     output = []
     inventory_allocation = InventoryAllocator(order, inventory)
     self.assertEqual(inventory_allocation.shipment_allocation(), output)
Example #19
0
 def test_inventory_blank(self):
     order = {'apple': 10}
     inventory = []
     order_output = []
     inventory_allocator = InventoryAllocator(order, inventory)
     self.assertEqual(inventory_allocator.allocate_inventory(),
                      order_output)
Example #20
0
 def test_inventory_insufficient(self):
     order = {'apple': 1}
     inventory = [{'name': 'owd', 'inventory': {'apple': 0}}]
     order_output = []
     inventory_allocator = InventoryAllocator(order, inventory)
     self.assertEqual(inventory_allocator.allocate_inventory(),
                      order_output)
Example #21
0
 def test_order_does_not_exist(self):
     order = {'apple': 15, 'banana': 20, 'orange': 20, 'kiwis': 10}
     inventory = [{
         'name': 'owd',
         'inventory': {
             'apple': 10,
             'banana': 5,
             'orange': 15
         }
     }, {
         'name': 'dm',
         'inventory': {
             'apple': 5,
             'banana': 20,
             'orange': 5
         }
     }, {
         'name': 'ca',
         'inventory': {
             'apple': 5,
             'orange': 10
         }
     }]
     order_output = []
     inventory_allocator = InventoryAllocator(order, inventory)
     self.assertEqual(inventory_allocator.allocate_inventory(),
                      order_output)
Example #22
0
    def test_enough_inventory_for_single_item(self):
        # single warehouse with single item in inventory -- exact quantity
        self.assertEqual([{
            'wh1': {
                'item1': 10
            }
        }],
                         InventoryAllocator().allocate_order(
                             {'item1': 10}, [Warehouse('wh1', {'item1': 10})]))

        # single warehouse with single item in inventory -- over quantity
        self.assertEqual([{
            'wh1': {
                'item1': 10
            }
        }],
                         InventoryAllocator().allocate_order(
                             {'item1': 10}, [Warehouse('wh1', {'item1': 20})]))

        # multiple warehouses -- multiple items in inventory -- over quantity in first warehouse
        self.assertEqual([{
            'wh1': {
                'item1': 10
            }
        }],
                         InventoryAllocator().allocate_order({'item1': 10}, [
                             Warehouse('wh1', {'item1': 10}),
                             Warehouse('wh2', {'item1': 20})
                         ]))

        # multiple warehouses -- multiple items in inventory -- not enough quantity in first warehouse
        self.assertEqual([{
            'wh1': {
                'item1': 4
            }
        }, {
            'wh2': {
                'item1': 6
            }
        }],
                         InventoryAllocator().allocate_order({'item1': 10}, [
                             Warehouse('wh1', {'item1': 4}),
                             Warehouse('wh2', {'item1': 20})
                         ]))

        # multiple warehouses -- exact quantity needed
        self.assertEqual([{
            'wh1': {
                'item1': 4
            }
        }, {
            'wh2': {
                'item1': 6
            }
        }],
                         InventoryAllocator().allocate_order({'item1': 10}, [
                             Warehouse('wh1', {'item1': 4}),
                             Warehouse('wh2', {'item1': 6})
                         ]))
Example #23
0
def test_partial_match1():
    allocator = InventoryAllocator()
    actual_result = allocator.cheapest_shipment_calculator({'apple': 10, 'orange': 7}, [
        {'name': 'abc', 'inventory': {'apple': 6, 'orange': 6}},
        {'name': 'def', 'inventory': {'banana': 4}},
        {'name': 'ghi', 'inventory': {'banana': 3, 'apple': 5}}])
    expected_result = []
    assert actual_result == expected_result
Example #24
0
 def test_no_allocations(self):
     order = {'apple': 1}
     warehouses = [{'name': 'owd', 'inventory': {'apple': 0}}]
     inv_alloc = InventoryAllocator(order, warehouses)
     actual = inv_alloc.find_cheapest_shipment_option()
     expected = []
     self.assertEqual(actual, expected,
                      'SOMETHING IS WRONG IN: no allocations')
Example #25
0
 def test_one_item_not_in_inventory(self):
     order = {"kiwi": 5}
     warehouses = self.select_warehouses([3, 2, 1, 0])
     expected = []
     inventory_allocator = InventoryAllocator(order, warehouses)
     shipment = inventory_allocator.allocate_inventory()
     self.assertEqual(shipment, expected,
                      "One item in the order, not in inventory")
Example #26
0
 def test_one_item_empty_inventory(self):
     order = {"apple": 5}
     warehouses = self.select_warehouses([0])
     expected = []
     inventory_allocator = InventoryAllocator(order, warehouses)
     shipment = inventory_allocator.allocate_inventory()
     self.assertEqual(shipment, expected,
                      "One item in the order, but inventory is empty")
Example #27
0
 def test_single_wh_oversufficient(self):
     order = {'apple': 1}
     warehouses = [{'name': 'owd', 'inventory': {'apple': 10000}}]
     inventory = {'apple': 10000}
     inv_alloc = InventoryAllocator(order, warehouses)
     actual = inv_alloc.check_warehouse_for_order(order, inventory)
     expected = {'apple': 1}
     self.assertEqual(actual, expected,
                      'SOMETHING IS WRONG IN: single wh oversufficient')
Example #28
0
 def test_multiple_items_some_not_in_inventory(self):
     order = {"apple": 5, "banana": 5, "peach": 3, "kiwi": 1}
     warehouses = self.select_warehouses([0, 1, 2, 3])
     expected = []
     inventory_allocator = InventoryAllocator(order, warehouses)
     shipment = inventory_allocator.allocate_inventory()
     self.assertEqual(
         shipment, expected,
         "Multiple items in the order, but some items is not in inventory")
Example #29
0
 def test_multiple_items_empty_inventory(self):
     order = {"apple": 5, "banana": 5, "orange": 3}
     warehouses = self.select_warehouses([0])
     expected = []
     inventory_allocator = InventoryAllocator(order, warehouses)
     shipment = inventory_allocator.allocate_inventory()
     self.assertEqual(
         shipment, expected,
         "Multiple items in the order, but inventory is empty")
 def testGetCheapestShipmentsMultipleOrderMultipleShipment(self):
     orders = {
         'apple': 5,
         'orange': 5,
         'banana': 5,
         'grape': 5,
     }
     warehouses = [{
         'name': 'owd',
         'inventory': {
             'apple': 5
         }
     }, {
         'name': 'dm',
         'inventory': {
             'orange': 5
         }
     }, {
         'name': 'bb',
         'inventory': {
             'banana': 5
         }
     }, {
         'name': 'gg',
         'inventory': {
             'grape': 5
         }
     }, {
         'name': 'all',
         'inventory': {
             'apple': 10,
             'orange': 10,
             'banana': 10,
             'grape': 10,
         }
     }]
     inventoryAllocator = InventoryAllocator()
     cheapestShipment = \
         inventoryAllocator.getCheapestShipments(orders, warehouses)
     self.assertEqual(cheapestShipment, [{
         'gg': {
             'grape': 5
         }
     }, {
         'bb': {
             'banana': 5
         }
     }, {
         'dm': {
             'orange': 5
         }
     }, {
         'owd': {
             'apple': 5
         }
     }])