コード例 #1
0
 def testGetCheapestShipmentsNotFound(self):
     orders = {'apple': 1}
     warehouses = [{'name': 'owd', 'inventory': {'apple': 0}}]
     inventoryAllocator = InventoryAllocator()
     cheapestShipment = \
         inventoryAllocator.getCheapestShipments(orders, warehouses)
     self.assertEqual(cheapestShipment, [])
コード例 #2
0
 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)
コード例 #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")
コード例 #4
0
 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
         }
     }])
コード例 #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
コード例 #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")
コード例 #7
0
 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)
コード例 #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")
コード例 #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)
コード例 #10
0
 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)
コード例 #11
0
 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)
コード例 #12
0
 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)
コード例 #13
0
 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)
コード例 #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})
                         ]))
コード例 #15
0
 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)
コード例 #16
0
 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}}])
コード例 #17
0
 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)
コード例 #18
0
 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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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})
                         ]))
コード例 #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
コード例 #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')
コード例 #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")
コード例 #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")
コード例 #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')
コード例 #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")
コード例 #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")
コード例 #30
0
 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
         }
     }])