def test_split_multipleWarehouses( self ): # Test to split an order across multiple warehouses if needed input1 = {"mango": 2, "apple": 6} input2 = [{ 'name': 'dm', 'inventory': { 'apple': 2, 'mangO': 2, "ban": 6 } }, { 'name': 'odm', 'inventory': { 'apple': 2, 'mango': 2 } }, { 'name': 'pdm', 'inventory': { 'apple': 3, 'mango': 3 } }] i1 = InventoryAllocator() self.assertEqual(i1.calculate_cheapest_shipment(input1, input2), [ '{ odm : { mango : 2 }}', [ '{ dm : { apple : 2 }}', '{ odm : { apple : 2 }}', '{ pdm : { apple : 3 }}' ] ])
def test_ship_completely_onewarehouse( self ): # Test to ship the order completely from one warehouse instead of shipping from multiple warehouses input1 = {"mango": 2, "apple": 6} input2 = [{ 'name': 'dm', 'inventory': { 'apple': 2, 'mangO': 2, "ban": 6 } }, { 'name': 'odm', 'inventory': { 'apple': 2, 'mango': 2 } }, { 'name': 'pdm', 'inventory': { 'apple': 3, 'mango': 3 } }, { 'name': 'mdm', 'inventory': { 'apple': 7, 'mango': 3 } }] i1 = InventoryAllocator() self.assertEqual(i1.calculate_cheapest_shipment(input1, input2), ['{ odm : { mango : 2 }}', '{ mdm : { apple : 7 }}'])
def test_insufficientInventory( self ): # Test to check if the're not enough orders in the inventory input1 = {"apple": 7} input2 = [{'name': 'dm', 'inventory': {'apple': 2, 'Banana': 2}}] i1 = InventoryAllocator() self.assertEqual(i1.calculate_cheapest_shipment(input1, input2), "No allocation")
def test_two(self): self.assertEqual( al.InventoryAllocator().calculateCheapestShipment( { 'apple': 5, 'banana': 5 }, [{ 'name': 'a', 'inventory': { 'apple': 5, 'orange': 3, 'banana': 3 } }, { 'name': 'b', 'inventory': { 'banana': 3, 'orange': 3 } }, { 'name': 'c', 'inventory': { 'apple': 5, 'orange': 6 } }]), [{ 'a': { 'apple': 5, 'banana': 3 } }, { 'b': { 'banana': 2 } }])
def test_five(self): self.assertEqual( al.InventoryAllocator().calculateCheapestShipment( { 'apple': 5, 'banana': 5, 'orange': 5 }, [{ 'name': 'owd', 'inventory': { 'apple': 5, 'orange': 10 } }, { 'name': 'dm', 'inventory': { 'banana': 5, 'orange': 10 } }]), [{ 'owd': { 'apple': 5, 'orange': 5 } }, { 'dm': { 'banana': 5 } }])
def test_four(self): self.assertEqual( al.InventoryAllocator().calculateCheapestShipment( {'apple': 10}, [{ 'name': 'owd', 'inventory': { 'apple': 5 } }, { 'name': 'dm', 'inventory': { 'apple': 5 } }, { 'name': 'xy', 'inventory': { 'apple': 5 } }]), [{ 'owd': { 'apple': 5 } }, { 'dm': { 'apple': 5 } }])
def test_6(self): self.assertEqual( ia.InventoryAllocator().get_cheapest_shipment({'apple': 5}, [{ 'name': 'a', 'inventory': { 'apple': 2 } }, { 'name': 'b', 'inventory': { 'apple': 2 } }, { 'name': 'c', 'inventory': { 'apple': 2 } }]), [{ 'a': { 'apple': 2 } }, { 'b': { 'apple': 2 } }, { 'c': { 'apple': 1 } }])
def test_9(self): self.assertEqual( ia.InventoryAllocator().get_cheapest_shipment( { 'apple': 3, 'orange': 3, 'banana': 3 }, [{ 'name': 'a', 'inventory': { 'apple': 1, 'orange': 1, 'banana': 1 } }, { 'name': 'b', 'inventory': { 'banana': 2, 'orange': 1 } }, { 'name': 'c', 'inventory': { 'apple': 3, 'orange': 0 } }]), [])
def test_one_warehouse(self): # Test to check in a single warehouse # p1 = Product("apple", "5") # p2 = Product("banana", "7") i1 = InventoryAllocator() result = i1.calculate_cheapest_shipment({"Banana": 1}, [{ "name": 'owd', "inventory": { "apple": 1 } }, { "name": 'dm', "inventory": { "apple": 2, "Banana": 2 } }]) self.assertEqual(result, ['{ dm : { Banana : 2 }}'])
def test_multipleWarehouses(self): # Test to check in multiple warehouses input1 = {"apple": 4} input2 = [{ 'name': 'dm', 'inventory': { 'apple': 4, 'Banana': 2 } }, { 'name': 'pdm', 'inventory': { 'apple': 4, 'mango': 2 } }] i1 = InventoryAllocator() self.assertEqual(i1.calculate_cheapest_shipment(input1, input2), ['{ dm : { apple : 4 }}'])
def test_5(self): self.assertEqual( ia.InventoryAllocator().get_cheapest_shipment({'apple': 2}, [{ 'name': 'a', 'inventory': { 'apple': 1 } }]), [])
def test_case_sensitivity( self): # Test to check if the orders are case sensitive input1 = {"APPLE": 1, "mango": 2} input2 = [{ 'name': 'dm', 'inventory': { 'apple': 2, 'Banana': 2 } }, { 'name': 'pdm', 'inventory': { 'apple': 3, 'mango': 2 } }] i1 = InventoryAllocator() self.assertEqual(i1.calculate_cheapest_shipment(input1, input2), ['{ pdm : { mango : 2 }}'])
def test_multiple_orders( self): # Test to check multiple orders in inventories input1 = {"apple": 2, "mango": 2} input2 = [{ 'name': 'dm', 'inventory': { 'apple': 2, 'Banana': 2 } }, { 'name': 'pdm', 'inventory': { 'apple': 3, 'mango': 2 } }] i1 = InventoryAllocator() self.assertEqual(i1.calculate_cheapest_shipment(input1, input2), ['{ dm : { apple : 2 }}', '{ pdm : { mango : 2 }}'])
def test_zero_order( self): # Test to check if there are orders with empty count input1 = {"apple": 0} input2 = [{ 'name': 'dm', 'inventory': { 'apple': 2, 'Banana': 2 } }, { 'name': 'pdm', 'inventory': { 'apple': 3, 'mango': 2 } }] i1 = InventoryAllocator() self.assertEqual(i1.calculate_cheapest_shipment(input1, input2), "No allocation")
def test_incorrect_unavailable_orders( self ): # Test to return no allocation if the orders are incorrect or unavailable input1 = {"app": 7, "ban": 6} input2 = [{ 'name': 'dm', 'inventory': { 'apple': 2, 'Banana': 2 } }, { 'name': 'pdm', 'inventory': { 'apple': 3, 'mango': 2 } }] i1 = InventoryAllocator() self.assertEqual(i1.calculate_cheapest_shipment(input1, input2), "No allocation")
def test_negative_order(self): order, warehouses = { "apple": -1 }, [{ "name": "owd", "inventory": { "apple": 5 } }] expected = [] self.assertEqual(InventoryAllocator.bestShipment(order, warehouses), expected)
def test_exact_match(self): order, warehouses = { "apple": 1 }, [{ "name": "owd", "inventory": { "apple": 1 } }] expected = [{"owd": {"apple": 1}}] self.assertEqual(InventoryAllocator.bestShipment(order, warehouses), expected)
def test_not_enough_inventory(self): order, warehouses = { "apple": 1 }, [{ "name": "owd", "inventory": { "apple": 0 } }] expected = [] self.assertEqual(InventoryAllocator.bestShipment(order, warehouses), expected)
def test_long_request(self): order, warehouses = { "apple": 10, "banana": 10, "peach": 10, "cherry": 10 }, [{ "name": "owd", "inventory": { "apple": 5, "banana": 2 } }, { "name": "dm", "inventory": { "apple": 5, "banana": 5, "peach": 3, "cherry": 5 } }, { "name": "td", "inventory": { "apple": 14, "banana": 4, "peach": 7, "cherry": 5 } }] expected = [{ "owd": { "apple": 5, "banana": 2 } }, { "dm": { "apple": 5, "banana": 5, "peach": 3, "cherry": 5 } }, { "td": { "banana": 3, "peach": 7, "cherry": 5 } }] self.assertEqual(InventoryAllocator.bestShipment(order, warehouses), expected)
def test_three(self): self.assertEqual( al.InventoryAllocator().calculateCheapestShipment( {'apple': 2}, [{ 'name': 'owd', 'inventory': { 'apple': 1 } }, { 'name': 'owd', 'inventory': { 'apple': 0 } }]), [])
def test_no_inventory(self): order, warehouses = { "banana": 10 }, [{ "name": "owd", "inventory": { "apple": 5 } }, { "name": "dm", "inventory": { "apple": 5 } }] expected = [] self.assertEqual(InventoryAllocator.bestShipment(order, warehouses), expected)
def test_eight(self): self.assertEqual( al.InventoryAllocator().calculateCheapestShipment( { 'apple': 5, 'orange': 5 }, [{ 'name': 'owd', 'inventory': { 'apple': 5, 'orange': 0 } }, { 'name': 'dm', 'inventory': { 'apple': 0, 'orange': 4 } }]), [])
def test_negative_inventory(self): order, warehouses = { "apple": 3 }, [{ "name": "owd", "inventory": { "apple": 5 } }, { "name": "dm", "inventory": { "apple": -5, "banana": 5, "peach": 3, "cherry": 5 } }] expected = [] self.assertEqual(InventoryAllocator.bestShipment(order, warehouses), expected)
def test_nine(self): self.assertEqual( al.InventoryAllocator().calculateCheapestShipment( {'apple': 5}, [{ 'name': 'owd', 'inventory': { 'apple': 2 } }, { 'name': 'dm', 'inventory': { 'apple': 2 } }, { 'name': 'abc', 'inventory': { 'apple': 0 } }, { 'name': 'def', 'inventory': { 'apple': 3 } }, { 'name': 'ghi', 'inventory': { 'apple': 3 } }]), [{ 'owd': { 'apple': 2 } }, { 'dm': { 'apple': 2 } }, { 'def': { 'apple': 1 } }])
def test_unknown_item(self): order, warehouses = { "apricot": 10 }, [{ "name": "owd", "inventory": { "apple": 5, "banana": 7 } }, { "name": "dm", "inventory": { "apple": 5, "banana": 5, "peach": 3, "cherry": 5 } }] expected = [] self.assertEqual(InventoryAllocator.bestShipment(order, warehouses), expected)
def setUp(self): self.inventory_allocator = InventoryAllocator.InventoryAllocator()
def test_empty_input(self): order, warehouses = {}, [] expected = [] self.assertEqual(InventoryAllocator.bestShipment(order, warehouses), expected)
def test_1(self): self.assertEqual(ia.InventoryAllocator().get_cheapest_shipment({}, []), [])
def test_2(self): self.assertEqual( ia.InventoryAllocator().get_cheapest_shipment({'apple': 1}, []), [])