def test_empty_dict(self): with self.assertRaises(Exception): profit({})
def test_example_a(self): ip = {"cost_price": 32.67, "sell_price": 45.00, "inventory": 1200} self.assertAlmostEqual(profit(ip), 14796)
def test_missing_inventory(self): with self.assertRaises(Exception): profit({"cost_price": 2.77, "sell_price": 7.95})
def test_negative_inventory(self): ip = {"cost_price": 225.89, "sell_price": 550.00, "inventory": -100} with self.assertRaises(Exception): profit(ip)
def test_missing_cost(self): with self.assertRaises(Exception): profit({"sell_price": 7.95, "inventory": 85001})
def test_missing_sell(self): with self.assertRaises(Exception): profit({"cost_price": 2.77, "inventory": 85001})
def testSuspended(self): self.assertEqual(profit.profit([]), 0)
def test_example_c(self): ip = {"cost_price": 2.77, "sell_price": 7.95, "inventory": 8500} self.assertAlmostEqual(profit(ip), 44030)
def testFlatlining(self): self.assertEqual(profit.profit([4, 4, 4]), 0)
def testTank(self): self.assertEqual(profit.profit([4, 2, 1]), -1)
def testProfitHighestSecondHalfDayNewHigh(self): self.assertEqual(profit.profit([2, 2, 5, 5, 1, 1, 7]), 6)
def testProfitHighestFirstHalfNewLowsAfter(self): self.assertEqual(profit.profit([2, 2, 5, 5, 1, 2, 3]), 3)
def testSkyrocket(self): self.assertEqual(profit.profit([1, 2, 5]), 4)