def test_calculate_integrity(self): for sheet_name, _ in dataframes.items(): months = list(range(1, 12 + 1)) data = calculate(sheet=sheet_name, months=months) for k, v in data.items(): buy_date = v[0][0] buy_price = v[0][1] sell_date = v[1][0] sell_price = v[1][1] max_profit = v[2] self.assertGreaterEqual(max_profit, 0, msg='Profits should be none-negative.') # In case the prices go down everyday, can't make a profit at all if buy_date is None: self.assertIsNone(sell_date) self.assertEqual(max_profit, 0, msg='There is no profits for this week.') # We can make a profit this week else: self.assertTrue(buy_date < sell_date, msg='Buy dates must be earlier than sell dates.') self.assertTrue(np.isclose(sell_price - buy_price, max_profit), msg='There might be some miscalculation of the maximum profits.')
def test_part2(s, expected): assert part2.calculate(s) == expected
def test_display(self): data = calculate(sheet='Gold Spot', months=[6]) print() print('################################# (Unit Test) ##############################################') display_data(data) print('############################################################################################')
def test_calculate_values(self): data = calculate(sheet='Palladium Spot', months=[1]) profits = [27.0, 78.0, 40.5] for i, (k, v) in enumerate(data.items()): profit = v[2] self.assertAlmostEqual(profit, profits[i])
def test2(s, n, expected): assert part2.calculate(s, n) == expected