class TestZoo(unittest.TestCase): def setUp(self): self.zoo_test = Zoo(50, 100000) self.bear_male = Animal("bear", 5, "Paul", "male", 200) self.bear_female = Animal("bear", 4, "Lucy", "female", 170) self.monkey = Animal("monkey", 2, "John", "male", 20) self.monkey_female = Animal("monkey", 2, "Molly", "female", 15) def test_init(self): self.assertEqual(self.zoo_test.capacity, 50) self.assertEqual(self.zoo_test.budget, 100000) def test_add_animal(self): self.zoo_test.add_animal(self.bear_male) self.zoo_test.add_animal(self.monkey) self.assertIn(self.bear_male, self.zoo_test.animals) self.assertIn(self.monkey, self.zoo_test.animals) def test_daily_income(self): self.zoo_test.add_animal(self.bear_male) self.zoo_test.add_animal(self.bear_female) self.zoo_test.add_animal(self.monkey) self.assertEqual(self.zoo_test.daily_income(), 180) def test_daily_outcome(self): self.zoo_test.add_animal(self.bear_male) self.zoo_test.add_animal(self.bear_female) self.assertEqual(self.zoo_test.daily_outcome(), 74) def test_is_not_pregnant(self): self.zoo_test.add_animal(self.bear_male) self.zoo_test.add_animal(self.bear_female) self.zoo_test.male_female_couple("bear") self.assertIn(self.bear_female, self.zoo_test.pregnant_animals) def test_pass_months(self): self.zoo_test.add_animal(self.bear_male) self.zoo_test.add_animal(self.bear_female) self.zoo_test.male_female_couple("bear") self.zoo_test.add_animal(self.monkey) self.zoo_test.add_animal(self.monkey_female) self.zoo_test.male_female_couple("monkey") self.zoo_test.pass_months(14) self.zoo_test.show_animals() def test_male_female_couple(self): self.zoo_test.add_animal(self.monkey) self.zoo_test.add_animal(self.bear_male) self.zoo_test.add_animal(self.bear_female) self.assertTrue(self.zoo_test.male_female_couple("bear"))
class TestZoo(unittest.TestCase): def setUp(self): self.new_zoo = Zoo(20, 5000) def test_init(self): self.assertEqual(20, self.new_zoo.capacity) self.assertEqual(5000, self.new_zoo.budget) self.assertEqual(0, len(self.new_zoo.dict_of_animals)) def test_accommodate(self): self.assertEqual({"Lion": 1}, self.new_zoo.accomodate("Lion")) self.assertEqual({"Lion": 2}, self.new_zoo.accomodate("Lion")) def test_dayly_income(self): self.new_zoo.accomodate("Lion") self.new_zoo.accomodate("Lion") self.new_zoo.accomodate("Koala") self.assertEqual(180, self.new_zoo.daily_income())
class ZooTests(unittest.TestCase): def setUp(self): self.tiger = Animal('tiger', 2, 'Pesho', 'male', 100) self.lion = Animal('lion', 5, 'Gosho', 'female', 120) self.goat = Animal('goat', 3, 'Kolio', 'male', 80) self.zoo = Zoo([self.tiger, self.lion, self.goat], 1000, 100000, 'Zoo') def test_zoo_get_animals(self): self.assertEqual([self.tiger, self.lion, self.goat], self.zoo.get_animals()) def test_zoo_get_capacity(self): self.assertEqual(1000, self.zoo.get_capacity()) def test_zoo_get_budget(self): self.assertEqual(100000, self.zoo.get_budget()) def test_zoo_get_name(self): self.assertEqual('Zoo', self.zoo.get_name()) @unittest.skip("Skip this.") def test_zoo_save(self): self.zoo.save() def test_zoo_income(self): self.assertEqual(180, self.zoo.daily_income()) def test_accomodate(self): self.zoo.accomodate(self.tiger) self.zoo.accomodate(self.lion) self.zoo.accomodate(self.goat) def test_daily_outcome(self): self.assertEqual(101, self.zoo.daily_outcome()) def test_simulate_period_of_time(self): self.zoo.simulate_time('months', 10) self.assertEqual(123700, self.zoo.get_budget())
def main(): print("Hello and welcome to Sofia Zoo!" + "\n" "Please, enter one of the following commands:" + "\n" "see_animals" + "\n" "accommodate <species> <name> <age> <gender> <weight>" + "\n" "move_to_habitat <species> <name>" + "\n" "simulate <interval_of_time> <period> " + "\n" "finish") sofia_zoo = Zoo(20, 200) intervals_of_time = {1: "days", 2: "weeks", 3: "months", 4: "years"} panda = Animal("panda", 32, "Pandio", "male", 50) tiger = Animal("tiger", 20, "Tonny", "male", 110) tigress = Animal("tiger", 24, "Anne", "female", 75) sofia_zoo.accomodate_new_animal(panda) sofia_zoo.accomodate_new_animal(tiger) sofia_zoo.accomodate_new_animal(tigress) command = input("Enter command > ") lst = command.split(" ") while lst[0] != "finish": if lst[0] == "see_animals": for animal in sofia_zoo.animals: print("{} : {}, {}, {}".format(animal.name, animal.species, animal.age, round(animal.weight, 2))) if lst[0] == "accommodate": sofia_zoo.accomodate_new_animal(Animal(lst[1], lst[3], lst[2], lst[4], lst[5])) if lst[0] == "move_to_habitat": sofia_zoo.remove_animal(lst[1], lst[2]) if lst[0] == "simulate": print("Simulation of the zoo for {} {}".format(lst[2], lst[1])) if lst[1] == intervals_of_time[1]: days = lst[2] elif lst[1] == intervals_of_time[2]: days = lst[2] * DAYS_IN_WEEK elif lst[1] == intervals_of_time[3]: days = lst[2] * DAYS_IN_MONTH else: days = lst[2] * DAYS_IN_YEAR for animal in sofia_zoo.animals: animal.grow(days / DAYS_IN_MONTH) print("Animals in the zoo:") for animal in sofia_zoo.animals: print("{} : {}, {}, {}".format(animal.name, animal.species, animal.age, round(animal.weight, 2))) animal.grow(days / DAYS_IN_MONTH) for day in range(days): for animal in sofia_zoo.animals: animal.eat() if sofia_zoo.die(animal): print(animal.name + " has died") sofia_zoo.daily_income() sofia_zoo.daily_outcome() if sofia_zoo.budget == 0: print("The zoo cannot affor to feed all animals") number_of_animals_in_zoo = len(sofia_zoo.animals) sofia_zoo.reproduce(choice(sofia_zoo.animals), choice(sofia_zoo.animals)) #sofia_zoo.reproduce(tiger, tigress) if len(sofia_zoo.animals) > number_of_animals_in_zoo: print("New baby is born") command = input("Enter command > ") lst = command.split(" ")