def test_inventory_blank(self): order = {'apple': 10} inventory = [] order_output = [] inventory_allocator = InventoryAllocator(order, inventory) self.assertEqual(inventory_allocator.allocate_inventory(), order_output)
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_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)
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")
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)
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_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 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")
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")
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")
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 test_one_item_one_warehouse(self): order = {"apple": 4} warehouses = self.select_warehouses([3, 2, 1, 0]) expected = [ { "w3": { "apple": 4 } }, ] inventory_allocator = InventoryAllocator(order, warehouses) shipment = inventory_allocator.allocate_inventory() self.assertEqual(shipment, expected, "One item in the order, fufilled by one warehouse")
def test_multiple_items_some_not_enough_inventory(self): order = { "apple": 15, "banana": 15, "orange": 3, } 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 somes items are not enough in inventory" )
def test_order_split_across_warehouses(self): order = {'apple': 10} inventory = [{ 'name': 'owd', 'inventory': { 'apple': 5 } }, { 'name': 'dm', 'inventory': { 'apple': 5 } }] order_output = [{'owd': {'apple': 5}}, {'dm': {'apple': 5}}] inventory_allocator = InventoryAllocator(order, inventory) self.assertEqual(inventory_allocator.allocate_inventory(), order_output)
def test_multiple_items_multiple_warehouses_permutation1(self): order = {"apple": 5, "banana": 5, "orange": 3} warehouses = self.select_warehouses([3, 2, 1, 0]) expected = [ { "w3": { "apple": 5, "orange": 3 } }, { "w4": { "banana": 5 } }, ] inventory_allocator = InventoryAllocator(order, warehouses) shipment = inventory_allocator.allocate_inventory() self.assertCountEqual( shipment, expected, "Multiple items in the order, fufilled by multiple warehouses")