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_mammal_class(self):
     """Test case:
     * Mammal should have a method called 'speak' that returns 'hello'.
     * Mammal should have a method called 'legs' that returns 2.
     * The output of 'legs' can be overwritten by modifying the _legs attribute of the Mammal class.
     """
     mammal = Mammal()
     self.assertEqual(mammal.speak(), 'hello')
     self.assertEqual(mammal.legs(), 2)
     mammal._legs = 4
     self.assertEqual(mammal.legs(), 4)
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)