Advertisement
horozov86

worker_testing

Jul 25th, 2023
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. import unittest
  2.  
  3. class WorkerTests(unittest.TestCase):
  4.     def test_initialization(self):
  5.         worker = Worker('Ivan Ivanov', 1000, 10)
  6.         self.assertEqual('Ivan Ivanov', worker.name)
  7.         self.assertEqual(1000, worker.salary)
  8.         self.assertEqual(10, worker.energy)
  9.         self.assertEqual(0, worker.money)
  10.  
  11.     def test_rest(self):
  12.         worker = Worker('Ivan Ivanov', 1000, 10)
  13.         worker.rest()
  14.         self.assertEqual(worker.energy, 11)
  15.  
  16.     def test_work_with_not_enough_energy(self):
  17.         worker = Worker('Ivan Ivanov', 1000, 0)
  18.         with self.assertRaises(Exception) as context:
  19.             worker.work()
  20.         self.assertEqual(str(context.exception), 'Not enough energy.')
  21.  
  22.     def test_work_with_negative_energy(self):
  23.         worker = Worker('Ivan Ivanov', 1000, -1)
  24.         with self.assertRaises(Exception) as context:
  25.             worker.work()
  26.         self.assertEqual(str(context.exception), 'Not enough energy.')
  27.  
  28.     def test_work_and_increase_money(self):
  29.         worker = Worker('Ivan Ivanov', 1000, 10)
  30.         worker.work()
  31.         self.assertEqual(worker.money, 1000)
  32.  
  33.     def test_decrease_energy(self):
  34.         worker = Worker('Ivan Ivanov', 1000, 10)
  35.         worker.work()
  36.         self.assertEqual(worker.energy, 9)
  37.  
  38.     def test_get_info_returns_correct_string(self):
  39.         worker = Worker('Ivan Ivanov', 1000, -1)
  40.         self.assertEqual(worker.get_info(), f'Ivan Ivanov has saved 0 money.')
  41.  
  42. if __name__ == '__main__':
  43.     unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement