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_zero_true(self): self.assertTrue( 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=0, balance=Decimal('8000'))))
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_ok(self): self.assertEqual(cost_of_set([LotData(1, 'test', Decimal('10'), 1)]), Decimal('100')) self.assertEqual( cost_of_set([LotData(1, 'test', Decimal('10.13'), 2)]), Decimal('202.6')) self.assertEqual( cost_of_set([ LotData(1, 'test', Decimal('10.13'), 2), LotData(1, 'test', Decimal('10.33'), 3), ]), Decimal('512.5'))
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_lot_data(), LotData(day=1, name='alfa-05', price=Decimal('100.2'), cnt=2)) mock_input.assert_called_with( """Введите <день> <название облигации в виде строки без пробелов> <цена> <количество> Чтобы закончить ввод данных нажмите Enter не заполняя поле :""")
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_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_count(self): self.assertEqual( cost_of_set([LotData(1, 'test', Decimal('10.13'), 0)]), Decimal('0'))
def test_zero_price(self): self.assertEqual(cost_of_set([LotData(1, 'test', Decimal('0'), 2)]), Decimal('0'))
def test_bond_cnt_zero(self, mock_input): self.assertEqual( ask_lot_data(), LotData(day=1, name='alfa-05', price=Decimal('100.2'), cnt=0))
def test_price_float(self, mock_input): self.assertEqual( ask_lot_data(), LotData(day=1, name='alfa-05', price=Decimal('100.2'), cnt=2))