def main(): db = Database("zoo.db") zoo = Zoo(50, 1000000000, db) simulation = Simulation(zoo) print("welcome to our zoo! enter help to get available commands") while True: commands = input("what'd you like to do? ").split(' ') command = commands[0] args = commands[1:] if command == 'help': print(instructions()) elif command == 'simulate': try: simulation.simulate(*args) except AttributeError: print('\n'.join(["wrong command or wrong arguments entered!", "maybe enter help again :)"])) elif command == 'exit': print('bye') exit(0) else: try: print(zoo.__getattribute__(command)(*args)) except (TypeError, AttributeError): print('\n'.join(["wrong command or wrong arguments entered!", "maybe enter help again :)"])) sm = Simulation(zoo) sm.simulation('months', 2)
class TestZoo(unittest.TestCase): def setUp(self): self.zoo1 = Zoo(30, 2000) def test_accomodate(self): self.zoo1.accommodate("Lion", 9, "Ivan", "male", 90) self.assertEqual(self.zoo1.animalsCollection[0].species, "Lion") self.assertEqual(self.zoo1.animalsCollection[0].name, "Ivan")
def update_zoos(self): zoos = [] all_zoos = self.get_zoos() for zoo in all_zoos: zoo = Zoo(zoo["name"], zoo["capacity"], zoo["budget"]) for animal in self.fetch_animals_from_zoo(zoo.get_name()): animal = Animal(animal["species"], animal["age"], animal["name"], animal["gender"], animal["weight"]) zoo.add_animal(animal) zoos.append(zoo) return zoos
class TestZoo(unittest.TestCase): def setUp(self): self.bear = Animal("bear", 12, "Pesho", "male", 60) self.panda = Animal("panda", 12, "Ivo", "male", 60) animals = [self.bear, self.panda] self.zoo = Zoo(animals, 10, 200) def test_init(self): self.assertEqual(self.zoo.animals, [self.bear, self.panda]) self.assertEqual(self.zoo.budget, 200) self.assertEqual(self.zoo.capacity, 10) def test_get_info(self): self.assertEqual(self.bear.get_info("gestation_period"), 3) def test_move_to_habitat(self): self.zoo.move_to_habitat("bear", "Pesho") self.assertEqual(self.zoo.animals, [self.panda]) def test_daily_incomes(self): self.assertEqual(self.zoo.get_daily_incomes(), 120) def test_accommodate_an_animal(self): bear2 = Animal("bear", 12, "Pesho2", "male", 60) self.zoo.accommodate_an_animal(bear2) self.assertEqual(self.zoo.animals, [self.bear, self.panda, bear2]) def test_remove_dead_animals(self): bear2 = Animal("bear", 12, "Pesho2", "male", 60) self.zoo.accommodate_an_animal(bear2) bear2.is_alive = False self.zoo.remove_dead_animals() self.assertEqual(self.zoo.animals, [self.bear, self.panda])
def test_worker_status(self): z = Zoo("My Zoo", 500, 3, 3) z.hire_worker(Vet("Leo", 35, 100)) z.hire_worker(Keeper("Tigy", 40, 100)) z.hire_worker(Caretaker("Chi", 24, 100)) res = z.workers_status() self.assertEqual( res, "You have 3 workers\n----- 1 Keepers:\nName: Tigy, Age: 40, Salary: 100\n----- 1 Caretakers:\nName: Chi, Age: 24, Salary: 100\n----- 1 Vets:\nName: Leo, Age: 35, Salary: 100" )
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_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.")
class testZoo(unittest.TestCase): def setUp(self): self.testZoo = Zoo(15, 12000) def test_get_animal_no_animals(self): self.assertEqual(0, self.testZoo.get_animal_count())
def read_file_csv(file_name): list_of_zoos = [] with open(file_name, 'r') as csv_file: reader = csv.reader(csv_file) for row in reader: list_of_zoos.append(Zoo(row[0], int(row[1]), int(row[2]))) return list_of_zoos
def test_zoo_init(self): z = Zoo("My Zoo", 1500, 6, 10) self.assertEqual(z._Zoo__animal_capacity, 6) self.assertEqual(z._Zoo__workers_capacity, 10) self.assertEqual(z._Zoo__budget, 1500) self.assertEqual(z.name, "My Zoo") self.assertEqual(z.animals, []) self.assertEqual(z.workers, [])
def test_zoo_pay_worker_no_budget(self): z = Zoo("Zoo", 200, 2, 2) z.hire_worker(Vet("John", 23, 100)) z.hire_worker(Keeper("Bill", 28, 150)) res = z.pay_workers() self.assertEqual( res, "You have no budget to pay your workers. They are unhappy")
def test_zoo_tend_animal_no_budget(self): z = Zoo("Zoo", 250, 2, 2) z.add_animal(Lion("John", "m", 2), 100) z.add_animal(Tiger("Bill", "f", 4), 100) res = z.tend_animals() self.assertEqual( res, "You have no budget to tend the animals. They are unhappy.")
def menu(): while True: print("-" * 40) menuInput = input( "1. Add visitor to park, 2. Add animal to park, 3. Show all people in the park, 4. Print all animals." ) if menuInput == "1": Zoo.visitorEnter() elif menuInput == "2": Zoo.createAnimals() elif menuInput == "3": Zoo.createWorker() elif menuInput == "4": Zoo.printPeople() elif menuInput == "5": Zoo.printAnimals() else: print("lool")
def test_zoo_pay_worker_success(self): z = Zoo("Zoo", 1500, 2, 2) z.hire_worker(Vet("John", 23, 100)) z.hire_worker(Keeper("Bill", 28, 150)) res = z.pay_workers() self.assertEqual(z._Zoo__budget, 1250) self.assertEqual( res, "You payed your workers. They are happy. Budget left: 1250")
def __init__(self, thisData, thisEerObject, thisCllrObject, thisConfig, thisExpName, thisDebug): Zoo.__init__(self, thisData, thisConfig, thisExpName, thisDebug) self.data = thisData self._eerObject = thisEerObject self._cllrObject = thisCllrObject self.config = thisConfig self._expName = thisExpName self._printToFilename = thisExpName self.debug = thisDebug self.plotType = "zoo_plot" self.title = self.data.getTitle() # All ellipses will have their own annotation. self._pointsWithAnnotation = [] # Directory to store animal data. self._outputPath = self.config.getOutputPath() self.aimsStdDev = [] self.agmsStdDev = [] self.fig = None
def create_zoo(self, owner_name: str) -> Optional[Zoo]: zoo_configs: Dict[ TCityName, ZooConfiguration] = ZOOsConfigBuilder().get_configs() config: ZooConfiguration = zoo_configs.get(self.name) if not config or not config.is_open_to_public: return None zoo_outline: ZooOutline = config.get_outline(owner_name, zoo_size=130) return Zoo(zoo_outline)
def test_zoo_tend_animal_success(self): z = Zoo("Zoo", 500, 2, 2) z.add_animal(Lion("John", "m", 2), 100) z.add_animal(Tiger("Bill", "f", 4), 100) res = z.tend_animals() self.assertEqual(z._Zoo__budget, 205) self.assertEqual( res, "You tended all the animals. They are happy. Budget left: 205")
def __init__(self, thisData, thisEerObject, thisCllerObject, thisConfig, thisExpName, thisDebug): Zoo.__init__(self, thisData, thisConfig, thisExpName, thisDebug) self.config = thisConfig self.data = thisData self._eerObject = thisEerObject self._cllrObject = thisCllerObject self._printToFilename = thisExpName self.debug = thisDebug # All ellipses will have their own annotation. self._pointsWithAnnotation = [] # Directory to store animal data. self._outputPath = self.config.getOutputPath() if self.debug: print('nrMeta:', self.data.getNrDistinctMetaDataValues()) self._title = self.data.getTitle() self.aimsStdDev = collections.defaultdict(float) self.agmsStdDev = collections.defaultdict(float) self.annotateEllipses = None
def setUp(self): self.first_animals = [Animal("tiger", 144, "DiviaLud", "male", 300), Animal("tiger", 96, "Pam", "female", 280), Animal("panda", 72, "Pom-Pom", "male", 340)] self.zoo = Zoo(self.first_animals, 100, 1200) self.animal1 = Animal("panda", 48, "Jully", "female", 350) self.animal2 = Animal("panda", 48, "Lilly", "female", 350) self.animal3 = Animal("tiger", 144, "DiviaLud", "male", 300) self.animal4 = Animal("tiger", 96, "Pam", "female", 280)
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 main(): a = Animal("cat", 1, 1) a.se_deplacer() s = Serpent("ss", 1, 1) s.se_deplacer() o = Oiseau("ss", 1, 1, 100) print(o.altmax) o.altmax = 150 print(o.altmax) o.se_deplacer() o.dosomething() z = Zoo([s, o]) z.dosomething() print(z) z.add_animal(a) print(z) print(z + z)
def main(): myzoo = Zoo() create_animal_table(cursor) while True: command = input('>>>') if command == 'list_animals' or command == 'l': see_animals(myzoo, cursor) elif command == 'simulate' or command == 's': interval = int(input('Enter interval of time in days:')) period = int(input('Enter period:')) for x in range (period): simulate(myzoo, interval, period, cursor) elif command == 'accommodate' or command == 'a': if myzoo.count_animals(cursor) >= myzoo.get_capacity(): print("Your zoo is full") print(myzoo.count_animals(cursor)) species = input('Enter species:') name = input('Enter name:') age = input('Enter age:') weight = input('Enter weight:') myzoo.accommodate(species, name, age, weight, cursor) conn.commit() elif command == 'move_to_habitat' or command == 'move': name = input('Name:') myzoo.move_to_habitat(name, cursor) print(name + ' has gone home!') conn.commit() elif command == 'exit': break conn.commit() conn.close()
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())
def test_zoo_fire_worker_success(self): z = Zoo("Zoo", 1500, 1, 1) z.hire_worker(Keeper("K", 45, 100)) res = z.fire_worker("K") self.assertEqual(res, "K fired successfully") self.assertEqual(z.workers, [])
class ZooGarden: def __init__(self): self.zoo = Zoo(50, 10000) def see_animals(self): if len(self.zoo.animals) != 0: for animal in self.zoo.animals: print(animal) else: print("\nThere are no animals yet. Accomodate some?") def accomodate(self, species, name, age, weight): gender = input("What gender is the animal?: ") self.zoo.accommodate(species, age, name, gender, weight) def move_to_habitat(self, species, name): has_such_animal = False for animal in self.zoo.animals: if animal.species == species and animal.name == name: print("{} is now a free {}!".format(animal.name, animal.species)) self.zoo.animals.remove(animal) Animal.SPECIES_NAMES[animal.species].remove(animal.name) has_such_animal = True if not has_such_animal: print("\nThere is no such animal in the zoo anyway.") def simulate(self, interval_of_time, period): if len(self.zoo.animals) != 0: time_in_months = self.__time_in_months(interval_of_time, period) for female in self.zoo.animals: for male in self.zoo.animals: self.zoo.reproduce(female, male) self.__grow_all_animals(time_in_months) print('\nTheese animals have grown:') self.see_animals() self.__print_dead_animals(self.zoo.dead_animals()) self.__could_budget_afford_food(time_in_months) self.__born_animals() else: print("\nThere are no animals yet. Accomodate some?") def __time_in_months(self, interval_of_time, period): if interval_of_time == 'days': return period * 1 / 30 # rough approximation elif interval_of_time == 'weeks': return period * 1 / 4 # rough approximation elif interval_of_time == 'months': return period elif interval_of_time == 'years': return period * 12 else: print("\nWrong interval of time, it should be " "days, weeks, months or years.") def __grow_all_animals(self, time_in_months): for animal in self.zoo.animals: animal.grow(time_in_months) def __print_dead_animals(self, list_dead_animals): if len(list_dead_animals) != 0: print("\nTheese animals had died:") for animal in list_dead_animals: print(animal) else: print("\nNo animals have died.") def __could_budget_afford_food(self, time_in_months): time_in_days = time_in_months * 30 # rough approximation self.zoo.budget += self.zoo.get_income() * time_in_days self.zoo.get_outcome() if self.zoo.budget >= 0: print("\nZoo's budget can afford feeding all animals:)") else: print("T\nhere aren't enough money to feed all animals." "Move some to habitat?") def __born_animals(self): babies = self.zoo.newborn_baby() if len(babies) != 0: print("\nZoo's babies are:") for baby in babies: print(baby) else: print("\nThere're no babies.") def show_database_species(self): file = open("database.json", "r") content = json.loads(file.read()) file.close() print("\nDatabase species are:") for species_key in content: print(species_key) def interface(self): print("\nWelcome to our Zoo! You can use one of the following" " commands:" "\n\nshow_database_species -> to know wich species" " are in our database" "\n\nsee_animals -> to see all current animals" "\n\naccomodate <species> <name> <age_in_months> <weight_in_" "kilos> -> to add animal in the zoo" "\n\nmove_to_habitat <species> <name> -> removes an animal from " "the Zoo and returns it to its natural habitat" "\n\nsimulate <interval_of_time> <period> -> shows what happens" " in the Zoo for that time" "\n - <interval_of_time> is 'days', 'weeks', 'months' or 'years'" "\n - <period> is a number" "\n\nexit -> to exit the program") while True: reply = input("\nYour choice: ") if reply == 'exit': break else: reply = reply.split() # make list of arguments if reply[0] == "see_animals": self.see_animals() elif reply[0] == "accomodate" and len(reply) == 5: self.accomodate(reply[1], reply[2], float(reply[3]), float(reply[4])) elif reply[0] == "move_to_habitat" and len(reply) == 3: self.move_to_habitat(reply[1], reply[2]) elif reply[0] == "simulate" and len(reply) == 3: self.simulate(reply[1], float(reply[2])) elif reply[0] == "show_database_species": self.show_database_species() else: print("Wrong command! Try again.")
from lion import Lion from tiger import Tiger from cheetah import Cheetah from keeper import Keeper from caretaker import Caretaker from vet import Vet from 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),
class TestZoo(unittest.TestCase): """docstring for ZooTest""" def setUp(self): self.zoo = Zoo("Sofia", 2, 3000) def test_atributes(self): self.assertEqual("Sofia", self.zoo.get_name()) self.assertEqual(2, self.zoo.get_capacity()) self.assertEqual([], self.zoo.get_animals()) def test_accomodate_animal(self): self.zoo.accommodate_animal("tiger", 18, "Zyblyo", "male", 19) self.assertEqual(1, len(self.zoo.get_animals())) self.assertEqual(True, self.zoo.accommodate_animal("tiger", 18, "Anastasij", "male", 19)) def test_see_animals(self): self.zoo.accommodate_animal("tiger", 18, "Zyblyo", "male", 19) expected = "Zyblyo\t - tiger, age: 18 years, weight: 19 kg" result = self.zoo.see_animals() self.assertEqual(expected, result) def test_remove_animal(self): self.zoo.accommodate_animal("tiger", 18, "Zyblyo", "male", 19) self.zoo.remove_animal("tiger", "Zyblyo") self.assertEqual(0, len(self.zoo.get_animals())) def test_move_animal(self): self.zoo.accommodate_animal("tiger", 18, "Spiridon", "male", 19) self.zoo.move_animal("tiger", "Spiridon") self.assertEqual(0, len(self.zoo.get_animals())) def test_daily_incomes(self): self.zoo.accommodate_animal("tiger", 18, "Tsveta", "female", 19) self.zoo.accommodate_animal("tiger", 18, "Svetla", "female", 19) self.assertEqual(120, self.zoo.daily_incomes()) def test_daily_expenses(self): self.zoo.accommodate_animal("tiger", 18, "Zyblyo", "male", 19) self.assertEqual(19 * 0.06 * 4, self.zoo.daily_expenses()) def test_born_animal(self): self.zoo.accommodate_animal("tiger", 18, "Snejan", "male", 19) self.zoo.accommodate_animal("tiger", 18, "Spiridonka", "female", 19) self.zoo.born_animal("tiger", "Spiridonka") self.assertEqual(3, len(self.zoo.get_animals())) def test_ready_to_give_birth(self): self.zoo.accommodate_animal("tiger", 18, "Snejan", "male", 19) self.zoo.accommodate_animal("tiger", 18, "Spiridonka", "female", 19) self.zoo.born_animal("tiger", "Spiridonka") self.assertFalse(self.zoo.born_animal("tiger", "Spiridonka")) def test_update_animals_from_database(self): self.assertEqual(0, len(self.zoo.get_animals())) self.db = self.zoo.get_database() animal1 = Animal("lion", 24, "Svetla", "female", 150) self.db.insert_animal(animal1) self.zoo.__animals = self.zoo.update_animals_from_database() self.assertEqual(1, len(self.zoo.get_animals())) first_animal = self.zoo.get_animals()[0] self.assertTrue(isinstance(first_animal, Animal)) def tearDown(self): call("rm Sofia.db", shell=True)
from zoo import Zoo from time import sleep import json z = Zoo() with open('./data/04_rgb_vertical_lines.json') as data_file: data = json.load(data_file) while True: for frame in data['data']: z.set_frame(frame) z.send_frame()
def test_zoo_hire_worker_success(self): z = Zoo("Some Zoo", 1500, 1, 1) res = z.hire_worker(Vet("I am Vet", 20, 500)) self.assertEqual(res, "I am Vet the Vet hired successfully") self.assertEqual(len(z.workers), 1) self.assertEqual(z._Zoo__workers_capacity, 1)
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 setUp(self): self.testZoo = Zoo(15, 12000)
def test_requirements(self): """ Creates zoo and cages: """ zoo = Zoo() cage_1 = Cage() cage_2 = Cage() """ Creation of animals: """ mouse = Mouse() wildcat = WildCat() lion = Lion() """ Attempt to add objects that are not cages to a zoo """ zoo.add_cages([mouse]) self.assertFalse(zoo.cages, [mouse]) """ Tests zoo with empty cages """ self.assertEqual(cage_1.n_of_animals(), 0) zoo.add_cages([cage_1, cage_2]) self.assertEqual(zoo.cages, [cage_1, cage_2]) """ Multiple addition of animals among repeated ones """ cage_1.add_animals([mouse, mouse, lion, lion, mouse]) # Set up to test more than one duplicated animal and different orders self.assertEqual(cage_1.animals_list, [mouse, lion]) """ Tests zoo attributes """ zoo.cages = [] zoo.add_cages([cage_1, cage_2]) self.assertEqual(zoo.cages, [cage_1, cage_2]) self.assertEqual(zoo.n_of_cages(), 2) self.assertEqual(zoo.n_of_animals(), 2) """ Tests competition between prey and predator """ cage_2.add_animals([mouse, wildcat, lion]) self.assertEqual(cage_2.animals_list, [lion]) """ Tests if animal already in another cage """ # ----- Should I do it? """ Attempt to add objects that are not animals to a cage """ cage_1.animals_list = [] cage_1.add_animals([zoo]) self.assertFalse(cage_1.animals_list, [zoo])
def test_zoo_profit(self): z = Zoo("Mine", 250, 2, 2) z.profit(250) self.assertEqual(z._Zoo__budget, 500)
>>> gold_fish.age_in_months 2 >>> gold_fish.make_sound() # Prints "Hum Hum" >>> gold_fish.breathe() # Prints "Breathe oxygen from water" Hint: You can remove the duplication of breathe by using inheritance appropirately. # Zoo A Zoo contains different types of animals which are mentioned above. Zoo has food reserve to feed animals. Write a Zoo class to implement this need and has the following features. add_food_to_reserve - Updates the amount of food in reserve >>> from zoo import Zoo >>> zoo = Zoo() >>> zoo.reserved_food_in_kgs 0 >>> zoo.add_food_to_reserve(10000000) >>> zoo.reserved_food_in_kgs 10000000 count_animals should return all the animals count in that zoo >>> zoo.count_animals() 0 add_animal - should add a new animal to the zoo >>> gold_fish = GoldFish(age_in_months=1, breed="Nemo", required_food_in_kgs=0.5) >>> zoo.add_animal(gold_fish) >>> zoo.count_animals() 1
def test_zoo_add_animal_success(self): z = Zoo("My Zoo", 1500, 6, 10) res = z.add_animal(Lion("Neo", "Male", 2), 1000) self.assertEqual(res, "Neo the Lion added to the zoo") self.assertEqual(len(z.animals), 1) self.assertEqual(z._Zoo__budget, 500)
def test_zoo_add_animal_no_budget(self): z = Zoo("My Zoo", 500, 6, 10) res = z.add_animal(Lion("Neo", "Male", 2), 1000) self.assertEqual(res, "Not enough budget") self.assertEqual(len(z.animals), 0) self.assertEqual(z._Zoo__budget, 500)
def test_zoo_add_animal_no_space(self): z = Zoo("My Zoo", 1500, 0, 10) res = z.add_animal(Lion("Neo", "Male", 2), 1000) self.assertEqual(res, "Not enough space for animal") self.assertEqual(len(z.animals), 0) self.assertEqual(z._Zoo__budget, 1500)
from zoo import Zoo from time import sleep z = Zoo() while True: sleepval = 0.00001 for x in range(z.NODE_COUNT): z.set_node(x, [255, 0, 0]) z.send_frame() sleep(sleepval) z.set_node(x, [0, 255, 0]) z.send_frame() sleep(sleepval) z.set_node(x, [0, 0, 255]) z.send_frame() sleep(sleepval) z.set_node(x, [255, 255, 255]) z.send_frame() sleep(sleepval)
def setUp(self): self.new_zoo = Zoo(20, 5000)
from zoo import Zoo from sozinova_class_giraffe import Giraffe z = Zoo() for i in range(4): a = Giraffe() a.color = '#2E4DFF' a.marker = '<' z.add_animal(a) z.start()
def test_zoo_fire_worker_unsuccessful(self): z = Zoo("Zoo", 1500, 1, 1) res = z.fire_worker("K") self.assertEqual(res, "There is no K in the zoo") self.assertEqual(z.workers, [])
#!/usr/bin/python from zoo import Zoo z = Zoo() while True: z.animate('TqkuOoKtmYI80', 50) z.animate('13FWPGF8YOJ8li', 50) z.animate('13mjtmImvfNf3', 50) z.animate('v2vdWBun97jtS', 100) z.animate('13ZOPnlbZJQd8c', 50) z.animate('koyjGfQHIZQKk', 200) z.animate('3o85xAg8LCrPOHxyMM', 80) z.animate('3o85xndeHesudYg6s0', 50) z.animate('wQgvjkPjg8wmc', 50) z.animate('5fBH6zaBGEqAPB8Tdkc', 50) z.animate('8iRAtRERgJEZy', 50) z.animate('PDXoH6PzNxmOA', 50) z.animate('xwmy7azQcHXCU', 50) z.animate('Q8Uq257UnqCze', 50) z.animate('Yr263I3crNiX6', 50) z.animate('fq8FnhT0UEOQw', 200) z.animate('QoGdi7FNqUiSA', 50) z.animate('FQAikp95qxSyQ', 50) z.animate('RkAwUt4dQF1tu', 50) z.animate('GY93OAKN5DMME', 100) z.animate('HLOaVqFZb6SNG', 50) z.animate('zjoFA3fCBdX6U', 50) z.animate('IK2MR7rp2eUOQ', 25) z.animate('tumblr_nnp3guf0bm1sn5m9vo1_500', 50) z.animate('tumblr_n7ldtazau91qc0s10o1_r2_500', 50)
class ZooTest(unittest.TestCase): def setUp(self): call('py create_animals_database.py', shell=True) self.db_conn = sqlite3.connect('animals.db') self.zoo = Zoo(self.db_conn, 2, 1000) self.zoo.animals = [Animal(self.db_conn, 'lion', 9, 'luv4o', 'male')] def test_see_animals(self): expected = ['luv4o : lion, 9, 67.5'] self.assertEqual(expected, self.zoo.see_animals()) def test_see_no_animals(self): self.zoo.animals = [] self.assertEqual([], self.zoo.see_animals()) def test_accomodate_animal(self): self.zoo.accomodate_animal('tiger', 'pe6o', 10, 'male') expected = ['luv4o : lion, 9, 67.5', 'pe6o : tiger, 10, 120.0'] self.assertEqual(expected, self.zoo.see_animals()) def test_accomodate_over_capacity(self): self.zoo.accomodate_animal('tiger', 'pe6o', 10, 'male') res = self.zoo.accomodate_animal('tiger', 'pe6ovica', 10, 'female') self.assertFalse(res) expected = ['luv4o : lion, 9, 67.5', 'pe6o : tiger, 10, 120.0'] self.assertEqual(expected, self.zoo.see_animals()) def test_move_to_habitat(self): result = self.zoo.move_to_habitat('lion', 'luv4o') expected = [] self.assertTrue(result) self.assertEqual(expected, self.zoo.see_animals()) def test_move_to_haibtat_with_non_existing_animal(self): result = self.zoo.move_to_habitat('asd', 'asd') self.assertFalse(result) def test_mate_animals(self): self.zoo.accomodate_animal('lion', 'pe6a', 10, 'female') self.zoo._mate_animals(9) self.assertEqual(3, len(self.zoo.animals)) def test_simulate(self): self.zoo.animals = [Animal(self.db_conn, 'lion', 1, 'luv4o', 'male')] expected = ['month 1:', 'luv4o : lion, 2, 15.0', 'No animals have died during the past month.', 'No animals were born during the past month.', 'The current budget is 1057.92'] self.assertEqual(expected, self.zoo.simulate('months', 1)) def tearDown(self): self.db_conn.commit() self.db_conn.close() call('rm -f animals.db', shell=True)
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"))
def setUp(self): call('py create_animals_database.py', shell=True) self.db_conn = sqlite3.connect('animals.db') self.zoo = Zoo(self.db_conn, 2, 1000) self.zoo.animals = [Animal(self.db_conn, 'lion', 9, 'luv4o', 'male')]
from zoo import Zoo, Cat if __name__ == '__main__': # 实例化动物园 z = Zoo('时间动物园') # 实例化一只猫,属性包括名字、类型、体型、性格 cat1 = Cat('大花猫 1', '食肉', '小', '温顺') # 增加一只猫到动物园 z.add_animal(cat1) # 动物园是否有猫这种动物 have_cat = hasattr(z, 'Cat')
class TestZoo(unittest.TestCase): def setUp(self): animals = [] capacity = 200 budget = 1000 self.my_zoo = Zoo(animals, capacity, budget) def test_init(self): self.assertListEqual(self.my_zoo.animals, []) self.assertEqual(self.my_zoo.capacity, 200) self.assertEqual(self.my_zoo.budget, 1000) self.assertEqual(self.my_zoo.DAILY_INCOME, 60) self.assertEqual(self.my_zoo.KILO_MEAT, 4) self.assertEqual(self.my_zoo.KILO_VEG_FOOD, 2) def test_accomodate(self): animal = Animal("Wolf", 2, "Kat", "male", 2,) self.my_zoo.accomodate(animal) self.assertListEqual(self.my_zoo.animals, [animal]) def test_calculate_incomes(self): animal = Animal("Wolf", 2, "Kat", "male", 2,) self.my_zoo.accomodate(animal) self.my_zoo.calculate_income() self.assertEqual(self.my_zoo.budget, 1060) def test_calculate_outcome(self): animal = Animal("Wolf", 2, "Kat", "male", 2) self.my_zoo.accomodate(animal) outcome = self.my_zoo.calculate_outcome() self.my_zoo.budget -= outcome self.assertEqual(self.my_zoo.budget, 999.6) def test_reproduce(self): animal = Animal("Wolf", 2, "Kat", "male", 2) self.my_zoo.accomodate(animal) animal = Animal("Wolf", 2, "Kate", "female", 3) self.my_zoo.accomodate(animal) self.my_zoo.reproduce()
def setUp(self): self.zoo = Zoo("Sofia", 2, 3000)
def setUp(self): animals = [] capacity = 200 budget = 1000 self.my_zoo = Zoo(animals, capacity, budget)
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')
ts = [] num_ts = 0 input_size = 0 output_size = 0 learning_rate = 0.0 if __name__ == "__main__": # initialise global variables SRC = 'big' # default source is big dataset if len(sys.argv) >= 2: SRC = sys.argv[1] # take user source # get questions and answers from the Zoo class Z = Zoo('data/' + SRC + '.csv') qs = Z.questions num_qs = len(qs) ts = Z.targets num_ts = len(ts) # hardcoded question limits for each dataset (+1 for last question guess) if SRC == 'big': question_limit = 13 + 1 elif SRC == 'medium': question_limit = 6 + 1 elif SRC == 'small': question_limit = 5 + 1 elif SRC == 'micro': question_limit = 4 + 1 else: question_limit = len(qs) # input and output size for nn are equal to the num qs and num ts respectively input_size = len(qs) output_size = len(ts)
def __init__(self): self.zoo = Zoo(50, 10000)
\n simulate <interval_of_time> <period>" return message def make_months(time, period): if period == "months": return time elif period == "days": return time / config.MONTH_DAYS elif period == "weeks": return time / config.MONTH_WEEKS elif period == "years": return time * config.MONTHS_YEAR #defining zoo and animals zoopark = Zoo(5, 5) puh_panda = Animal("panda", 3, "Puh", "male", 100) zoopark.add_animal(puh_panda) gosho_tiger = Animal("tiger", 4, "Gosho", "male", 30) zoopark.add_animal(gosho_tiger) ivan_tiger = Animal("tiger", 4, "Ivan", "male", 30) zoopark.add_animal(ivan_tiger) def main(): print(start_message) while True: command = split_command_str(input("Enter command>")) if the_command(command, "see_animals"): print_arr(zoopark)
def setUp(self): self.zoo1 = Zoo(30, 2000)
def test_zoo_hire_worker_no_space(self): z = Zoo("Some Zoo", 1500, 1, 0) res = z.hire_worker(Vet("I am Vet", 20, 500)) self.assertEqual(res, "Not enough space for worker") self.assertEqual(len(z.workers), 0) self.assertEqual(z._Zoo__workers_capacity, 0)