Advertisement
horozov86

mammal_testing_directly_after_basic_class!!!

Jul 26th, 2023
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. class Mammal:
  2.     def __init__(self, name, mammal_type, sound):
  3.         self.name = name
  4.         self.type = mammal_type
  5.         self.sound = sound
  6.         self.__kingdom = "animals"
  7.  
  8.     def make_sound(self):
  9.         return f"{self.name} makes {self.sound}"
  10.  
  11.     def get_kingdom(self):
  12.         return self.__kingdom
  13.  
  14.     def info(self):
  15.         return f"{self.name} is of type {self.type}"
  16.        
  17.        
  18. import unittest
  19.  
  20. class TestMammal(unittest.TestCase):
  21.     def setUp(self):
  22.         self.mammal = Mammal('some_name', 'some_type', 'some_sound')
  23.        
  24.     def test_correct_initialization(self):
  25.         self.assertEqual('some_name', self.mammal.name)
  26.         self.assertEqual('some_type', self.mammal.type)
  27.         self.assertEqual('some_sound', self.mammal.sound)
  28.        
  29.     def test_if_make_sound_is_correct(self):
  30.         result = self.mammal.make_sound()
  31.         self.assertEqual(f"some_name makes some_sound", result)
  32.        
  33.     def test_get_kingdom_is_correct(self):
  34.         result = self. mammal.get_kingdom()
  35.         self.assertEqual('animals', result)
  36.        
  37.     def test_get_info(self):
  38.         result = self.mammal.info()
  39.         self.assertEqual(f"some_name is of type some_type", result)
  40.        
  41.        
  42.        
  43. if __name__ == '__main__':
  44.     unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement