Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Mammal:
- def __init__(self, name, mammal_type, sound):
- self.name = name
- self.type = mammal_type
- self.sound = sound
- self.__kingdom = "animals"
- def make_sound(self):
- return f"{self.name} makes {self.sound}"
- def get_kingdom(self):
- return self.__kingdom
- def info(self):
- return f"{self.name} is of type {self.type}"
- import unittest
- class TestMammal(unittest.TestCase):
- def setUp(self):
- self.mammal = Mammal('some_name', 'some_type', 'some_sound')
- def test_correct_initialization(self):
- self.assertEqual('some_name', self.mammal.name)
- self.assertEqual('some_type', self.mammal.type)
- self.assertEqual('some_sound', self.mammal.sound)
- def test_if_make_sound_is_correct(self):
- result = self.mammal.make_sound()
- self.assertEqual(f"some_name makes some_sound", result)
- def test_get_kingdom_is_correct(self):
- result = self. mammal.get_kingdom()
- self.assertEqual('animals', result)
- def test_get_info(self):
- result = self.mammal.info()
- self.assertEqual(f"some_name is of type some_type", result)
- if __name__ == '__main__':
- unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement