def test_requirements(self): zoo = Zoo() cage1 = Cage() cage2 = Cage() zoo.add_cage(cage1) zoo.add_cage(cage2) self.assertEqual( zoo.number_of_cages(), 2 ) # At any time, you should be able to find out how many cages are in the zoo. lion = Lion() hyena = Hyena() gazelle = Gazelle() wildebeest = Wildebeest() cage1.add_animal(lion) cage2.add_animal(gazelle) self.assertEqual(cage1.contents, [lion]) # Put different animals in the cages self.assertTrue( lion.species) # Each animal should be of a particular species self.assertTrue( lion.name ) # Each animal should have a name given to them by the zookeeper cage1.add_animal(hyena) cage2.add_animal(wildebeest) self.assertEqual( cage1.contents, [lion, hyena]) # Find out which animals are in a particular cage self.assertEqual(cage2.contents, [gazelle, wildebeest ]) # Find out which animals are in a particular cage with patch("builtins.print") as mock_print: prey_cage = Cage() predator = Lion(name='Predator') prey = Gazelle(name='Prey') prey_cage.add_animal(prey) prey_cage.add_animal(predator) mock_print.assert_called_once_with("Predator ate Prey.")
def test_requirements(self): zoo = Zoo() cage1 = Cage() cage2 = Cage() zoo.add_cage(cage1) zoo.add_cage(cage2) self.assertEqual(zoo.number_of_cages(), 2) # At any time, you should be able to find out how many cages are in the zoo. lion = Lion() hyena = Hyena() gazelle = Gazelle() wildebeest = Wildebeest() cage1.add_animal(lion) cage2.add_animal(gazelle) self.assertEqual(cage1.contents, [lion]) # Put different animals in the cages self.assertTrue(lion.species) # Each animal should be of a particular species self.assertTrue(lion.name) # Each animal should have a name given to them by the zookeeper cage1.add_animal(hyena) cage2.add_animal(wildebeest) self.assertEqual(cage1.contents, [lion, hyena]) # Find out which animals are in a particular cage self.assertEqual(cage2.contents, [gazelle, wildebeest]) # Find out which animals are in a particular cage with patch("builtins.print") as mock_print: prey_cage = Cage() predator = Lion(name='Predator') prey = Gazelle(name='Prey') prey_cage.add_animal(prey) prey_cage.add_animal(predator) mock_print.assert_called_once_with("Predator ate Prey.")