def animals_status(self): lions_count = 0 tigers_count = 0 cheetahs_count = 0 lions_repr = [] tigers_repr = [] cheetahs_repr = [] for animal in self.animals: if animal.__class__.__name__ == "Tiger": tigers_count += 1 tigers_repr.append(Tiger.__repr__(animal)) elif animal.__class__.__name__ == "Lion": lions_count += 1 lions_repr.append(Lion.__repr__(animal)) elif animal.__class__.__name__ == "Cheetah": cheetahs_count += 1 cheetahs_repr.append(Cheetah.__repr__(animal)) lions_repr = "\n".join(lions_repr) tigers_repr = "\n".join(tigers_repr) cheetahs_repr = "\n".join(cheetahs_repr) return f"""You have {len(self.animals)} animals
def test_animal_status(self): z = Zoo("My Zoo", 500, 3, 3) z.add_animal(Lion("Leo", "Male", 3), 100) z.add_animal(Tiger("Tigy", "Female", 4), 100) z.add_animal(Cheetah("Chi", "Female", 2), 100) res = z.animals_status() self.assertEqual(res, "You have 3 animals\n----- 1 Lions:\nName: Leo, Age: 3, Gender: Male\n----- 1 Tigers:\nName: Tigy, Age: 4, Gender: Female\n----- 1 Cheetahs:\nName: Chi, Age: 2, Gender: Female")
def test_cheetah_repr(self): c = Cheetah("n", "f", 2) res = str(c) self.assertEqual(res, "Name: n, Age: 2, Gender: f")
def test_cheetah_get_needs(self): c = Cheetah("r", "m", 6) res = c.get_needs() self.assertEqual(res, 60)
def test_cheetah_init(self): c = Cheetah("l", "f", 3) self.assertEqual(c.name, "l") self.assertEqual(c.gender, "f") self.assertEqual(c.age, 3)
from project.caretaker import Caretaker from project.cheetah import Cheetah from project.keeper import Keeper from project.lion import Lion from project.tiger import Tiger from project.vet import Vet from project.zoo import Zoo zoo = Zoo("Zootopia", 3000, 5, 8) # Animals creation animals = [ Cheetah("Cheeto", "Male", 2), Cheetah("Cheetia", "Female", 1), Lion("Simba", "Male", 4), Tiger("Zuba", "Male", 3), Tiger("Tigeria", "Female", 1), Lion("Nala", "Female", 4) ] # Animal prices prices = [200, 190, 204, 156, 211, 140] # Workers creation workers = [ Keeper("John", 26, 100), Keeper("Adam", 29, 80), Keeper("Anna", 31, 95), Caretaker("Bill", 21, 68), Caretaker("Marie", 32, 105), Caretaker("Stacy", 35, 140),
from project.caretaker import Caretaker from project.cheetah import Cheetah from project.keeper import Keeper from project.lion import Lion from project.tiger import Tiger from project.vet import Vet from project.zoo import Zoo zoo = Zoo("Zootopia", 3000, 5, 8) # Animals creation animals = [Cheetah("Cheeto", "Male", 2), Cheetah("Cheetia", "Female", 1), Lion("Simba", "Male", 4), Tiger("Zuba", "Male", 3), Tiger("Tigeria", "Female", 1), Lion("Nala", "Female", 4)] # Animal prices prices = [200, 190, 204, 156, 211, 140] # Workers creation workers = [Keeper("John", 26, 100), Keeper("Adam", 29, 80), Keeper("Anna", 31, 95), Caretaker("Bill", 21, 68), Caretaker("Marie", 32, 105), Caretaker("Stacy", 35, 140), Vet("Peter", 40, 300), Vet("Kasey", 37, 280), Vet("Sam", 29, 220)] # Adding all animals for i in range(len(animals)): animal = animals[i] price = prices[i] print(zoo.add_animal(animal, price)) # Adding all workers for worker in workers: print(zoo.hire_worker(worker)) # Tending animals
from project.caretaker import Caretaker from project.cheetah import Cheetah from project.keeper import Keeper from project.lion import Lion from project.tiger import Tiger from project.vet import Vet from project.zoo import Zoo zoo = Zoo("Zootopia", 3000, 5, 8) # Animals creation animals = [Cheetah("Cheeto", "Male", 2), Cheetah("Cheetia", "Female", 1), Lion("Simba", "Male", 4), Tiger("Zuba", "Male", 3), Tiger("Tigeria", "Female", 1), Lion("Nala", "Female", 4)] # Animal prices prices = [200, 190, 204, 156, 211, 140] # Workers creation workers = [Keeper("John", 26, 100), Keeper("Adam", 29, 80), Keeper("Anna", 31, 95), Caretaker("Bill", 21, 68), Caretaker("Marie", 32, 105), Caretaker("Stacy", 35, 140), Vet("Peter", 40, 300), Vet("Kasey", 37, 280), Vet("Sam", 29, 220)] # Adding all animals for i in range(len(animals)): animal = animals[i] price = prices[i] print(zoo.add_animal(animal, price)) # Adding all workers for worker in workers:
def test_cheetah_get_needs(self): c = Cheetah("r", "m", 6) res = c.money_for_care self.assertEqual(res, 60)