Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import unittest
- class WorkerTests(unittest.TestCase):
- def setUp(self):
- self.worker = Worker('Ivan Ivanov', 1000, 10)
- def test_initialization(self):
- self.assertEqual('Ivan Ivanov', self.worker.name)
- self.assertEqual(1000, self.worker.salary)
- self.assertEqual(10, self.worker.energy)
- self.assertEqual(0, self.worker.money)
- def test_energy_incremented(self):
- worker = Worker('Ivan Ivanov', 1000, 10)
- worker.rest()
- self.assertEqual(worker.energy, 11)
- def test_energy_equal_to_zero(self):
- worker = Worker('Ivan Ivanov', 1000, 0)
- with self.assertRaises(Exception) as context:
- worker.work()
- self.assertEqual(str(context.exception), 'Not enough energy.')
- def test_energy_negative(self):
- worker = Worker('Ivan Ivanov', 1000, -1)
- with self.assertRaises(Exception) as context:
- worker.work()
- self.assertEqual(str(context.exception), 'Not enough energy.')
- def test_increase_worker_money(self):
- self.worker.work()
- self.assertEqual(self.worker.salary, 1000)
- def test_worker_energy_decreased(self):
- self.worker.work()
- self.assertEqual(self.worker.energy, 9)
- def test_get_info_returns_correct_string(self):
- self.assertEqual(self.worker.get_info(), f'Ivan Ivanov has saved 0 money.')
- if __name__ == '__main__':
- unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement