Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import unittest
- class WorkerTests(unittest.TestCase):
- def test_initialization(self):
- worker = Worker('Ivan Ivanov', 1000, 10)
- self.assertEqual('Ivan Ivanov', worker.name)
- self.assertEqual(1000, worker.salary)
- self.assertEqual(10, worker.energy)
- self.assertEqual(0, worker.money)
- def test_rest(self):
- worker = Worker('Ivan Ivanov', 1000, 10)
- worker.rest()
- self.assertEqual(worker.energy, 11)
- def test_work_with_not_enough_energy(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_work_with_negative_energy(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_work_and_increase_money(self):
- worker = Worker('Ivan Ivanov', 1000, 10)
- worker.work()
- self.assertEqual(worker.money, 1000)
- def test_decrease_energy(self):
- worker = Worker('Ivan Ivanov', 1000, 10)
- worker.work()
- self.assertEqual(worker.energy, 9)
- def test_get_info_returns_correct_string(self):
- worker = Worker('Ivan Ivanov', 1000, -1)
- self.assertEqual(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