def test_ok(self): self.assertEqual( calculate([ LotData(day=1, name='alfa-05', price=Decimal('100.2'), cnt=2), LotData(day=2, name='alfa-05', price=Decimal('101.5'), cnt=5), LotData( day=2, name='gazprom-17', price=Decimal('100.0'), cnt=2), ], Params(day_cnt=2, lot_per_day_cnt=2, balance=Decimal('8000'))), (Decimal('135'), ( LotData(day=2, name='alfa-05', price=Decimal('101.5'), cnt=5), LotData( day=2, name='gazprom-17', price=Decimal('100.0'), cnt=2), ))) self.assertEqual( calculate([ LotData(day=1, name='alfa-05', price=Decimal('100.2'), cnt=2), LotData(day=2, name='alfa-05', price=Decimal('101.5'), cnt=5), LotData( day=2, name='gazprom-17', price=Decimal('100.0'), cnt=2), LotData( day=2, name='gazprom-18', price=Decimal('110.0'), cnt=1), ], Params(day_cnt=2, lot_per_day_cnt=2, balance=Decimal('8000'))), (Decimal('135'), ( LotData(day=2, name='alfa-05', price=Decimal('101.5'), cnt=5), LotData( day=2, name='gazprom-17', price=Decimal('100.0'), cnt=2), )))
def test_zero_price(self): self.assertEqual( profit_of_set([ LotData(day=2, name='alfa-05', price=Decimal('0'), cnt=1), ], Params(day_cnt=2, lot_per_day_cnt=2, balance=Decimal('8000'))), Decimal('1030')) self.assertEqual( profit_of_set([ LotData(day=1, name='alfa-05', price=Decimal('0'), cnt=1), ], Params(day_cnt=2, lot_per_day_cnt=2, balance=Decimal('8000'))), Decimal('1031'))
def test_false(self): self.assertFalse( is_exceeded_lots_per_day([ LotData(1, 'test', Decimal('10.13'), 2), LotData(1, 'test', Decimal('10.33'), 3), ], Params(day_cnt=2, lot_per_day_cnt=2, balance=Decimal('8000')))) self.assertFalse( is_exceeded_lots_per_day([ LotData(1, 'test', Decimal('10.13'), 2), LotData(1, 'test', Decimal('10.33'), 3), LotData(1, 'test', Decimal('10.33'), 3), ], Params(day_cnt=2, lot_per_day_cnt=3, balance=Decimal('8000'))))
class MainTest(TestCase): @patch('task_2.ask_nms_params', return_value=Params(day_cnt=2, lot_per_day_cnt=2, balance=Decimal('8000'))) @patch('task_2.ask_lot_data', side_effect=[ LotData(day=1, name='alfa-05', price=Decimal('100.2'), cnt=2), LotData(day=2, name='alfa-05', price=Decimal('101.5'), cnt=5), LotData(day=2, name='gazprom-17', price=Decimal('100.0'), cnt=2), None ]) @patch('task_2.print') def test_ok(self, mock_print, mock_ask_lot_data, mock_ask_nms_params): main() self.assertEqual(mock_print.call_count, 7) self.assertEqual( mock_print.mock_calls, list( map(lambda x: call(x), [ '\nДобавлено!\n', '\nДобавлено!\n', '\nДобавлено!\n', Decimal('135.000'), '2 alfa-05 101.5 5', '2 gazprom-17 100.0 2', '' ])))
def test_ok(self): self.assertEqual( profit_of_set([ LotData(day=2, name='alfa-05', price=Decimal('101.5'), cnt=5), LotData( day=2, name='gazprom-17', price=Decimal('100.0'), cnt=2), ], Params(day_cnt=2, lot_per_day_cnt=2, balance=Decimal('8000'))), Decimal('135')) self.assertEqual( profit_of_set([ LotData(day=1, name='alfa-05', price=Decimal('101.5'), cnt=5), LotData( day=2, name='gazprom-17', price=Decimal('100.0'), cnt=2), ], Params(day_cnt=2, lot_per_day_cnt=2, balance=Decimal('8000'))), Decimal('140'))
def test_ok(self, mock_input): self.assertEqual( ask_nms_params(), Params(day_cnt=2, lot_per_day_cnt=2, balance=Decimal('8000'))) mock_input.assert_called_with( """Введите через пробел числа, например, 2 2 8000: #1 Близжайщее кол-во дней за которые трейдеру известна информация о том какие предложения по облигациям будут на рынке #2 Кол-во лотов доступных каждый день #3 Сумма денежных средст трейдера :""")
def test_balance(self): self.assertEqual( calculate([ LotData(day=1, name='alfa-04', price=Decimal('100'), cnt=1), LotData(day=1, name='alfa-05', price=Decimal('100'), cnt=1), LotData(day=1, name='alfa-06', price=Decimal('100'), cnt=1), LotData(day=1, name='alfa-07', price=Decimal('102'), cnt=1), LotData(day=2, name='gaz-04', price=Decimal('99'), cnt=1), LotData(day=2, name='gaz-05', price=Decimal('100'), cnt=1), LotData(day=2, name='gaz-06', price=Decimal('101'), cnt=1), ], Params(day_cnt=2, lot_per_day_cnt=2, balance=Decimal('1000'))), (Decimal('40'), (LotData(day=2, name='gaz-04', price=Decimal('99'), cnt=1), )))
def test_day_zero(self, mock_input): self.assertEqual( ask_nms_params(), Params(day_cnt=0, lot_per_day_cnt=2, balance=Decimal('2')))
def test_empty(self): self.assertEqual( profit_of_set([], Params(day_cnt=2, lot_per_day_cnt=2, balance=Decimal('8000'))), Decimal('0'))
def test_empty(self): self.assertFalse( is_exceeded_lots_per_day([], Params(day_cnt=2, lot_per_day_cnt=0, balance=Decimal('8000'))))