Example #1
0
 def test_dog_class(self):
     """Test case:
     * Dog's speak method should return 'arf'.
     * Dog's 'legs' method should return the output of Mammal's legs method multiplied by 2.
     """
     mammal = Mammal()
     dog = Dog()
     self.assertEqual(dog.speak(), 'arf')
     self.assertEqual(dog.legs(), mammal.legs()*2)
Example #2
0
    def test_dog2_class(self):
        """Test case: Should behave like Dog's class
        * Dog's speak method should return 'arf'.
        * Dog's 'legs' method should return the output of Mammal's legs method multiplied by 2.
        """
        dog = Dog()
        dog2 = Dog2()
        self.assertEqual(dog2.speak(), dog.speak())
        self.assertEqual(dog2.legs(), dog.legs())

        # Option with no inheritance.
        dog3 = Dog3()
        self.assertEqual(dog3.speak(), dog.speak())
        self.assertEqual(dog3.legs(), dog.legs())
Example #3
0
    def test_init_attr_not_accesible_when_preceded_by_double_underscore(self):
        """Test case:
        * test that illustrates an attribute defined in the `__init__` method of 'Mammal' is not
        accessible to Dog or Cat when preceded by a double-underscore, but an attribute
        preceded by a single-underscore or no underscore is.
        """
        mammal = Mammal()
        cat = Cat()
        dog = Dog()

        self.assertEqual(cat.info_type(), mammal.info_type())       # __type not accessible to Cat (is not able to overwrite it)
        self.assertNotEqual(cat.info_temp(), mammal.info_temp())    # _temp accessible to Cat (is able to overwrite it)
        self.assertNotEqual(cat.info_body(), mammal.info_body())    # body accessible to Cat (is able to overwrite it)

        self.assertEqual(dog.info_type(), mammal.info_type())       # __type not accessible to Dog (is not able to overwrite it)
        self.assertNotEqual(dog.info_temp(), mammal.info_temp())    # _temp accessible to Dog (is able to overwrite it)
        self.assertNotEqual(dog.info_body(), mammal.info_body())    # body accessible to Dog (is able to overwrite it)