Beispiel #1
0
 def __init__(self, x, y, r):
     Animal.__init__(self, x, y, r)
     is_swimming = True
     self.tail = Tail(self)
     self.destination_x = x
     self.destination_y = y
     return
Beispiel #2
0
 def test_make_reproduction_moves_false3_one_couple(self):
     yana_tiger = Animal("tiger", 5, "Yana", "female", 30)
     self.zoopark.animals.append(yana_tiger)
     gosho_tiger = Animal("panda", 4, "Gosho", "male", 30)
     self.zoopark.animals.append(gosho_tiger)
     self.zoopark.make_reproduction_moves()
     self.assertFalse(yana_tiger.is_pregnant)
Beispiel #3
0
 def test_zoo_budget_update(self):
     ivan_tiger = Animal("tiger", 4, "Gosho", "male", 30)
     self.zoopark.animals.append(ivan_tiger)
     gosho_tiger = Animal("tiger", 4, "Gosho", "male", 30)
     self.zoopark.animals.append(gosho_tiger)
     self.zoopark._update_zoo_budget(2)
     self.assertEqual(self.zoopark.budget, 2981)
Beispiel #4
0
 def __init__(self, name, age, height, weight, color, job, school,
              university):
     Animal.__init__(self, name, age, height, weight, color)
     self.university = university
     self.job = job
     self.school = school
     self.friends = []
Beispiel #5
0
class TestAnimal(unittest.TestCase):

    def setUp(self):
        self.animal = Animal('Snake', 'Pypy', 12, 'male', 63)

    def test_animal_init(self):
        self.assertEqual(self.animal.species, 'Snake')
        self.assertEqual(self.animal.name, 'Pypy')
        self.assertEqual(self.animal.age, 12)
        self.assertEqual(self.animal.weight, 63)

    def test_animal_eat(self):
        self.animal.eat()
        self.assertEqual(self.animal.weight, 66.15)

    def test_animal_grow(self):
        self.animal.grow()
        self.assertEqual(self.animal.age, 13)
        self.assertEqual(self.animal.weight, 64.26)

    def test_animal_dies(self):
        result = []
        for i in range(100):
            result.append(self.animal.is_dead())
        self.assertIn(True, result)
        self.assertIn(False, result)
def addAnimal():
    try:
        print("Please type details of Animal: ")
        gender = input("Gender: ")
        birth = input("Birth: ")
        color = input("Color: ")

        print("\nPlease type Environment Conditions: \n")
        humidity = input("Relative Humidity: ")
        size = input("Enclosure Size (m2): ")
        temperature = input("Temperature: ")
        hours_of_light = input("Hours of light per day: ")

        flag = 0
        while (flag == 0):
            animalNo = str(randint(1000, 9999))
            animalList = appliaction.getAllAnimal()
            if len(animalList) != 0:
                for animal in animalList:
                    if animalNo not in animal.animalNo:
                        flag = 1
            else:
                flag = 1
        newAnimal = Animal()
        newAnimal.set(animalNo, gender, birth, color, humidity, size,
                      temperature, hours_of_light)
        appliaction.addAnimalToList(newAnimal)
        print("\nA new animal added successfully\n")
    except:
        print("\nSome Error occured, try again.\n")
    main()
class TestAnimal(unittest.TestCase):

    def setUp(self):

        self.my_animal = Animal("cat", 5, "Cattie", "female", 4, 15, True, 9)

    def test_init(self):

        self.assertEqual(self.my_animal.species, "cat")
        self.assertEqual(self.my_animal.age, 5)
        self.assertEqual(self.my_animal.name, "Cattie")
        self.assertEqual(self.my_animal.gender, "female")
        self.assertEqual(self.my_animal.weight, 4)
        self.assertEqual(self.my_animal.life_expectancy, 15)
        self.assertTrue(self.my_animal.is_vegetarian)

    def test_grow(self):

        self.my_animal.grow(2, 2)
        self.assertEqual(self.my_animal.age, 7)
        self.assertEqual(self.my_animal.weight, 6)

    def test_eat(self):

        self.my_animal.eat(5000)
        self.assertEqual(self.my_animal.weight, 5004)
 def test_1(self):
     a1 = Animal(0, 0, 0, 5, [1, 2, 3, 4, 5, 6, 7, 8])
     a2 = Animal(0, 0, 0, 5, [1, 2, 3, 4, 5, 6, 7, 8])
     animal_list = [a1, a2]
     newWorld = World(10, 10, 2, 2, 1, 1)
     wmanager = WorldManager(newWorld, animal_list, 2, 0, 10)
     wmanager.Start()
Beispiel #9
0
	def breed_constant(self):
		"""Iterates the entire Population to a new generation, calculating the number of offspring of each Animal with CONSTANT population size"""
		calc_payoff 	= np.vectorize(lambda x: x.lifetime_payoff(self._positions))
		lifetime_payoff = calc_payoff(self._animals)
		mean_payoff 	= np.mean(lifetime_payoff)

		if (mean_payoff == 0):
			raise RuntimeError("Mean payoff of population decreased to 0. Check your parameters!")
		else:
			payoff_factor = lifetime_payoff/mean_payoff

		offspring = np.random.poisson(lam=payoff_factor)
		born_animals = np.repeat(self._animals,offspring)
		mutate_pop = np.vectorize(lambda x: Animal(x.mutate(),x.position))
		new_animals = mutate_pop(born_animals)

		N = len(new_animals)
		if self._constants["verbose"]:
			print("\n\nAnimals per environment: {0}".format(self._positions))
			print("Population size: {0}\tMean payoff: {1:.2f}".format(N,mean_payoff))
		if (N > self._constants["population_size"]):
			new_animals = np.random.choice(new_animals,self._constants["population_size"]\
							,replace=False)
		elif (N < self._constants["population_size"]):
			clone_candidates = np.random.choice(new_animals,\
						self._constants["population_size"] - N)
			clones = [Animal(x.genes,x.position) for x in clone_candidates]
			new_animals = np.append(new_animals,clones)

		self._animals 	= new_animals
		self._positions = self.positions()
Beispiel #10
0
 def test_add_animal_same_name(self):
     gosho_tiger = Animal("tiger", 4, "Gosho", "male", 30)
     self.zoopark.add_animal(gosho_tiger)
     ivan_tiger = Animal("tiger", 4, "Gosho", "male", 30)
     self.zoopark.add_animal(ivan_tiger)
     self.assertEqual(len(self.zoopark.animals), 1)
     self.assertEqual(self.zoopark.animals[0], gosho_tiger)
Beispiel #11
0
 def test_make_reproduction_moves_true_one_couple(self):
     yana_tiger = Animal("tiger", 8, "Yana", "female", 30)
     self.zoopark.animals.append(yana_tiger)
     gosho_tiger = Animal("tiger", 4, "Gosho", "male", 30)
     self.zoopark.animals.append(gosho_tiger)
     self.zoopark.make_reproduction_moves()
     self.assertTrue(yana_tiger.is_pregnant)
     self.assertEqual(yana_tiger.gestination_period, 0)
Beispiel #12
0
 def test_actions_with_pregnant_one(self):
     yana_tiger = Animal("tiger", 8, "Yana", "female", 30)
     yana_tiger.is_pregnant = True
     self.zoopark.animals.append(yana_tiger)
     self.zoopark.actions_with_pregnant_one(5)
     self.assertEqual(yana_tiger.gestination_period, 5)
     self.assertEqual(len(self.zoopark.animals), 1)
     self.assertEqual(yana_tiger.relax_period, 8)
Beispiel #13
0
 def __init__(self):
     super(Animal, self).__init__(
     )  #moge zainicjalizowac klase nie dziedziczac jej , poza jakakolwiek klasa np w jakiejs funkcji che wywol;ac sobie np klase animal-> super
     #lub:
     Animal.__init__(self)
     self.dlugosc_skrzydla = 0
     self.kolor_upierzenia = ''
     self.plec = ''
Beispiel #14
0
 def test_actions_with_pregnant_one(self):
     yana_tiger = Animal("tiger", 8, "Yana", "female", 30)
     yana_tiger.is_pregnant = True
     self.zoopark.animals.append(yana_tiger)
     self.zoopark.actions_with_pregnant_one(5)
     self.assertEqual(yana_tiger.gestination_period, 5)
     self.assertEqual(len(self.zoopark.animals), 1)
     self.assertEqual(yana_tiger.relax_period, 8)
Beispiel #15
0
    def __init__(self, resolution):
        print("starting up")
        pygame.init()
        self.screen = pygame.display.set_mode(resolution)

        self.title = "catdogdogcat"

        self.running = True
        self.paused = False
        self.highscore_screen = False
        self.game_loosed = False

        self.FPS = 30
        self.playtime = 0.0

        # Things for game difficulty
        self.gravity = 1
        self.gravity_tick = 0.5
        self.difficulty = 1
        self.difficulty_frequency_sec = 10
        self.difficulty_tick_time = 10

        self.clock = pygame.time.Clock()

        # time in seconds when a new obstacle needs to be added to the game
        self.obstacle_tick_time = 0
        self.obstacles = pygame.sprite.Group()

        # things that pop up by your head when you eat food
        self.score_bubbles = pygame.sprite.Group()

        # player score
        self.points = 0
        self.MIN_SCORE = -9

        self.move_ticker = 0

        logo = pygame.image.load(path.join("assets", "logo32x32.png"))
        pygame.display.set_icon(logo)
        pygame.display.set_caption(self.title)

        self.background_image = \
            pygame.image.load(path.join("assets", "background.png")).convert()

        self.animal = Animal(self.screen)

        self.fonts = {
            'score': pygame.font.Font('assets/GochiHand-Regular.ttf', 50),
            'title': pygame.font.Font('assets/GochiHand-Regular.ttf', 100),
            'menu': pygame.font.Font('assets/GochiHand-Regular.ttf', 30)
        }

        # menu
        self.text_color = (0, 0, 0)
        self.menu_color = (0, 0, 255)
        self.menu_item_texts = ["Start", "Highscores", "Quit"]
        self.menu_items = []
        self.selected_menu_item = 0
Beispiel #16
0
 def test_make_reproduction_moves_false2_one_couple(self):
     yana_tiger = Animal("tiger", 5, "Yana", "female", 30)
     yana_tiger.is_pregnant = True
     yana_tiger.gestination_period = 4
     self.zoopark.animals.append(yana_tiger)
     gosho_tiger = Animal("tiger", 4, "Gosho", "male", 30)
     self.zoopark.animals.append(gosho_tiger)
     self.zoopark.make_reproduction_moves()
     self.assertEqual(yana_tiger.gestination_period, 4)
Beispiel #17
0
 def insert_animal(self, genome):
     a = Animal(genome, PHEROMONES)
     a.teleport(random.randrange(0, self.width, 1),
                random.randrange(0, self.height, 1),
                random.uniform(0, 6.28))
     self.animals.append(a)
     self.objects.append(
         Food(random.randrange(0, self.width, 1),
              random.randrange(0, self.height, 1), 10))
Beispiel #18
0
def main():
    a = Animal()
    d = Dog()
    c = Cat()
    d.speak()
    c.speak()
    c.sleep()
    d.sleep()
    a.sleep()
Beispiel #19
0
 def test_add_animal_full_zoo(self):
     self.zoopark.add_animal(self.puh_panda)
     gosho_tiger = Animal("tiger", 4, "Gosho", "male", 30)
     self.zoopark.add_animal(gosho_tiger)
     ivan_tiger = Animal("tiger", 4, "Ivan", "male", 30)
     self.zoopark.add_animal(ivan_tiger)
     self.assertEqual(len(self.zoopark.animals), 2)
     self.assertEqual(self.zoopark.animals[0], self.puh_panda)
     self.assertEqual(self.zoopark.animals[1], gosho_tiger)
Beispiel #20
0
 def giveUp(self, previousAnimal, previousAnswer, player):
     player.addPlayerWin()
     animalType = raw_input('Hvilken type dyr var det? ')
     animalQuestion = raw_input('Gi et spoersmaal for ' + animalType + ': ')
     animal = Animal(animalType)
     animal.setQuestion(animalQuestion)
     if previousAnswer == 'N':
         previousAnimal.setLeftLeaf(animal)
     else:
         previousAnimal.setRightLeaf(animal)
Beispiel #21
0
 def test_actions_with_pregnant_one_new_baby(self):
     yana_tiger = Animal("tiger", 8, "Yana", "female", 30)
     yana_tiger.is_pregnant = True
     self.zoopark.animals.append(yana_tiger)
     self.zoopark.actions_with_pregnant_one(8)
     self.assertEqual(yana_tiger.gestination_period, 0)
     self.assertEqual(len(self.zoopark.animals), 2)
     self.assertEqual(yana_tiger.relax_period, 2)
     baby = self.zoopark.animals[1]
     self.assertEqual(baby.age, 2)
Beispiel #22
0
    def __init__(self, world, loc, ai):
        Animal.__init__(self, world, loc)
        self.speed = 3.0
        self.angle = 0.0

        self.action = 'nothing'
        self.ai = ai

        self.max_speed = 5.0
        self.actions = []
Beispiel #23
0
 def test_actions_with_pregnant_one_new_baby(self):
     yana_tiger = Animal("tiger", 8, "Yana", "female", 30)
     yana_tiger.is_pregnant = True
     self.zoopark.animals.append(yana_tiger)
     self.zoopark.actions_with_pregnant_one(8)
     self.assertEqual(yana_tiger.gestination_period, 0)
     self.assertEqual(len(self.zoopark.animals), 2)
     self.assertEqual(yana_tiger.relax_period, 2)
     baby = self.zoopark.animals[1]
     self.assertEqual(baby.age, 2)
Beispiel #24
0
    def __init__(self, world, pos: (float, float), speed: float):
        """
		Initializes the Rabbit

		Args:
			world (World): The world
			pos ( (float, float) ): Starting position
			speed (float): Rabbit speed
		"""

        Animal.__init__(self, world, pos, speed)
        self.sight = 150
Beispiel #25
0
    def test_get_age(self):
        animal_instance = Animal('Dog', 12)
        self.assertEquals(animal_instance.get_age(), 12)

        animal_instance = Animal('Dog', 12)
        self.assertEquals(animal_instance.get_age(), 12)

        animal_instance = Animal('Dog', 12)
        self.assertEquals(animal_instance.get_age(), 12)
Beispiel #26
0
 def insert_animal(self, genome):
     a = Animal(genome, PHEROMONES)
     a.teleport(
         random.randrange(0, self.width, 1),
         random.randrange(0, self.height, 1),
         random.uniform(0, 6.28)
     )
     self.animals.append(a)
     self.objects.append(Food(
         random.randrange(0, self.width, 1),
         random.randrange(0, self.height, 1),
         10
     ))
Beispiel #27
0
def get_animal():
    ear_tag = request.args.get("get_eartag")
    if ear_tag:
        animals = Animal.objects(status="ACTIVE", ear_tag__icontains=ear_tag)[:10]
    else:
        animals = Animal.objects(status="ACTIVE")[:5]
    results = list()
    if animals:
        for animal in animals:
            results.append(animal.to_mongo())
        return jsonify({"animals": results})
    else:
        return jsonify(results)
Beispiel #28
0
    def __init__(self):
        Animal.__init__(self)
        self.numOwels = 0
        self.rocks = 0
        self.MouseNumber = 0

        self.currentOwlSlots = []
        self.currentStoneSlots = []
        self.allMices = []

        self.totalSteps = 0

        self.randomSpawn()
Beispiel #29
0
def test_mange():
    medor = Animal('Medor', 600)
    kiki = Animal('Kiki', 20)
    medor(kiki)  # Médor mange Kiki
    assert medor.estVivant()
    assert not kiki.estVivant()
    assert kiki.masse == 0
    assert medor.masse == 620
    kiki = Animal("Kiki Jr.", 20)
    kiki(medor)  # Kiki Jr. mange Médor
    assert not medor.estVivant()
    assert kiki.estVivant()
    assert kiki.masse == 22
    assert medor.masse == 618  # Médor a perdu du poids en se faisant manger!
Beispiel #30
0
 def test_make_reproduction_moves_true_some_animals(self):
     yana_tiger = Animal("tiger", 8, "Yana", "female", 30)
     self.zoopark.animals.append(yana_tiger)
     gosho_tiger = Animal("tiger", 4, "Gosho", "male", 30)
     self.zoopark.animals.append(gosho_tiger)
     self.zoopark.animals.append(self.puh_panda)
     puha_panda_f = Animal("panda", 8, "Vanya", "female", 100)
     self.zoopark.animals.append(puha_panda_f)
     dif_animal = Animal("bear", 8, "Vasilka", "female", 100)
     self.zoopark.animals.append(dif_animal)
     self.zoopark.make_reproduction_moves()
     self.assertTrue(yana_tiger.is_pregnant)
     self.assertEqual(yana_tiger.gestination_period, 0)
     self.assertTrue(puha_panda_f.is_pregnant)
     self.assertEqual(puha_panda_f.gestination_period, 0)
Beispiel #31
0
 def test_animal_can_walk(self):
     """ tests that a newly created animal object can walk and errors will be raised if needed """
     test_animal = Animal()
     with self.assertRaises(ValueError):
         test_animal.walk()
     test_animal.set_legs(4)
     test_animal.walk()
     self.assertEqual(test_animal.speed, .4)
Beispiel #32
0
 def restart(self):
     self.animals = [Animal(self) for _ in range(35)]
     self.animals_to_add = []
     self.dead_animals = []
     self.empty_food = []
     self.food = [self._make_random_food() for _ in range(80)]
     self.time = 0
Beispiel #33
0
 def open_animal(self, path, tracknames=None):
     a = Animal(path)  # init it just to parse its name
     exec_lines = ("try: %s; \n"
                   "except NameError: %s = Animal(%r)\n"
                   "%s.load(%r)" %
                   (a.name, a.name, path, a.name, tracknames))
     self.ipw.execute(exec_lines)
Beispiel #34
0
 def breed(self):
     if self.empty_slots <= 0:
         return self.animals
     else:
         self.animals.append(Animal())
         self.empty_slots -= 1
         return self.empty_slots
Beispiel #35
0
    def __init__(self, space_width, space_height, animal_count, pred_count,
                 genomes):
        self.pool = Pool()
        self.manager = Manager()

        self.width = space_width
        self.height = space_height
        self.genomes = genomes
        self.predators = [
            Predator(random.randrange(0, self.width, 1),
                     random.randrange(0, self.height, 1))
            for _ in range(pred_count)
        ]
        self.animals = [
            Animal(random.choice(genomes), PHEROMONES)
            for _ in range(animal_count)
        ]
        self.objects = [
            Food(random.randrange(0, self.width, 1),
                 random.randrange(0, self.height, 1), 10)
            for _ in range(animal_count)
        ]
        for a in self.animals:
            a.teleport(random.randrange(0, self.width, 1),
                       random.randrange(0, self.height, 1),
                       random.uniform(0, 6.28))
        self.next_food = random.expovariate(1.0 / FOOD_PERIOD)
        self.next_poison = random.expovariate(1.0 / POISON_PERIOD)
        self.pheromones = self.manager.list([])
        self.next_breed = random.expovariate(1.0 / BREEDING_PERIOD)
        self.new_genomes = []
Beispiel #36
0
 def test_growing(self):
     self.zoopark.animals.append(self.puh_panda)
     yana_tiger = Animal("tiger", 8, "Yana", "female", 30)
     self.zoopark.animals.append(yana_tiger)
     self.zoopark.grow_animals(5)
     self.assertEqual(self.puh_panda.age, 8)
     self.assertEqual(yana_tiger.age, 13)
Beispiel #37
0
 def _read_data(self):
     zoo_path = path.relpath("datasets/zoo.data")
     zoo_file = open(zoo_path)
     animals = []
     for line in zoo_file:
         animals.append(Animal(line.strip()))
     return animals
Beispiel #38
0
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])
Beispiel #39
0
 def test_pregnancy_simulated_time_pregnant_female(self):
     self.animal_female = Animal("bear", 13, "Pollinka 1", 'female', 10.0)
     self.animal_female.pregnant_period = 4
     self.animal_female.non_pregnant_period = None
     self.animal_female.grow(3)
     self.assertEqual(6, self.animal_female.pregnant_period)
     self.assertEqual(None, self.animal_female.non_pregnant_period)
Beispiel #40
0
    def reproduce(self, male_parent, female_parent):
        assert isinstance(male_parent, Animal)
        assert isinstance(female_parent, Animal)
        assert male_parent.sex == "male"
        assert female_parent.sex == "female"

        children = []
        reproductive_capacity = round((male_parent.reproductive_capacity + female_parent.reproductive_capacity)/2, 0)
        if reproductive_capacity <= 0:
            return []

        for i in range(int(reproductive_capacity)):
            child = Animal()
            child.inherit(male_parent, female_parent)
            child.mutate()
            children.append(child)
        return children
Beispiel #41
0
class AnimalTests(unittest.TestCase):
    def setUp(self):
        self.test_animal = Animal("Tiger", 5, "Gencho", "male", 350, 10, "carnivore",
        50, 400, 25, (1, 50))

    def test_animal_grow(self):
        self.test_animal.grow(2)
        self.assertEqual(self.test_animal.weight, 400)
        self.assertEqual(self.test_animal.age, 7)

    def test_animal_consume(self):
        self.assertEqual(self.test_animal.consume(), 7)

    def test_animal_is_alive(self):
        self.assertTrue(self.test_animal.is_alive)
        for x in range(0, 10):
            self.test_animal.should_die()
        self.assertFalse(self.test_animal.is_alive)
Beispiel #42
0
    def reproduce(self, animal1, animal2):
        min_age = 24
        cannot_get_pregnant = 6
        if animal1.age < min_age or animal2.age < min_age:
            return "Cannot reproduce. Animals are too young"

        # Must discuss these changes!
        if animal1.species == animal2.species and animal1.gender != animal2.gender:
            if animal1.gender == "female" and animal1.age - animal1.last_pregnancy >= cannot_get_pregnant:
                animal1.last_pregnancy = animal1.age + animal1.gestation_period
            elif animal2.gender == "female" and animal2.age - animal2.last_pregnancy >= cannot_get_pregnant:
                animal2.last_pregnancy = animal2.age + animal2.gestation_period
            baby = Animal(animal1.species, 0, None, self.gender_baby(), animal1.newborn_weight)
            while True:
                baby.name = self.name_baby(baby)
                if self.does_name_exist(baby.name, baby) is False:
                    break
            self.accommodate(baby)
            return baby
        else:
            return "Cannot reproduce"
Beispiel #43
0
class TestAnimal(unittest.TestCase):
    def setUp(self):
        self.animal = Animal("tiger", 10, "Tig", "male", 175)

    def test_properties(self):
        self.assertEqual(self.animal.specie, "tiger")
        self.assertEqual(self.animal.age, 10)
        self.assertEqual(self.animal.name, "Tig")
        self.assertEqual(self.animal.gender, "male")
        self.assertEqual(self.animal.weight, 175)

    def test_grow(self):
        self.animal.grow(250, 15.1)
        self.assertEqual(11, self.animal.age)
        self.assertEqual(190.1, self.animal.weight)

    def test_grow_again(self):
        self.animal.grow(175, 2)
        self.assertEqual(11, self.animal.age)
        self.assertEqual(175, self.animal.weight)

    def test_eat(self):
        self.assertEqual(17.5, self.animal.eat(0.1))

    def test_die(self):
        is_dead = self.animal.die(3)
        self.assertEqual(False, is_dead)
Beispiel #44
0
class TestAnimal(unittest.TestCase):

    def setUp(self):
        self.animal = Animal("tiger", "DiviaLud", "male", 10, 150)
        self.animal2 = Animal("tiger", "DiviaLud", "male", 10, 175)

    def test_init(self):
        self.assertEqual("tiger", self.animal.species)
        self.assertEqual(120, self.animal.age)
        self.assertEqual("DiviaLud", self.animal.name)
        self.assertEqual("male", self.animal.gender)
        self.assertEqual(150, self.animal.weight)

    def test_eat(self):
        food_in_kilos = self.animal.eat()
        self.assertEqual(4.5, food_in_kilos)

    def test_grows(self):
        self.animal.grows()
        self.animal2.grows()
        self.assertEqual(121, self.animal.age)
        self.assertEqual(160, self.animal.weight)
        self.assertEqual(180, self.animal2.weight)

    def test_chance_of_dying(self):
        chance = self.animal.chance_of_dying()
        self.assertEqual(0.5, chance)
class Animal_test(unittest.TestCase):

    def setUp(self):
        self.my_animal = Animal("bear", 5, "puh", "m", 150, 10)

    def test_init(self):
        self.assertEqual(self.my_animal.species, "bear")
        self.assertEqual(self.my_animal.age, 5)
        self.assertEqual(self.my_animal.name, "puh")
        self.assertEqual(self.my_animal.gender, "m")
        self.assertEqual(self.my_animal.weight, 150)
        self.assertTrue(self.my_animal.alive)
        self.assertEqual(self.my_animal.life_expectancy, 10)

    def test_grow(self):
        self.my_animal.grow()
        self.assertEqual(self.my_animal.age, 6)
        self.assertEqual(self.my_animal.weight, 151)

    def test_eat(self):
        self.my_animal.eat()
        self.assertEqual(self.my_animal.weight, 151)

    def test_should_die(self):
        flag_die = False
        flag_alive = False
        for i in range(0, 100):
            self.my_animal.should_die()
            if not self.my_animal.alive:
                flag_die = True
            else:
                flag_alive = True
        self.assertTrue(flag_die and flag_alive)
Beispiel #46
0
class ZooTests(unittest.TestCase):
    def setUp(self):
        self.zoo = Zoo("Alexandria Zoo", 2, 1000)
        self.tiger_vitaly = Animal("tiger", 1, "Vitaly", "male", 180)
        self.lion_alex = Animal("lion", 1, "Alex", "male", 210)
        self.hippo_gloria = Animal("hippo", 2, "Gloria", "female", 1600)

    def test_get_zoo_name(self):
        self.assertEqual("Alexandria Zoo", self.zoo.get_name())

    def test_get_zoo_max_capacity(self):
        self.assertEqual(2, self.zoo.get_max_capacity())

    def test_get_zoo_budget(self):
        self.assertEqual(1000, self.zoo.get_budget())

    def test_get_animals(self):
        self.assertEqual("", self.zoo.get_animals())

    def test_add_animal(self):
        self.assertTrue(self.zoo.add_animal(self.tiger_vitaly))
        self.assertEqual("<Vitaly>: <tiger>, <1>, <180>", self.zoo.get_animals())

    def test_add_animal_when_no_space(self):
        self.assertTrue(self.zoo.add_animal(self.tiger_vitaly))
        self.assertEqual("<Vitaly>: <tiger>, <1>, <180>", self.zoo.get_animals())
        self.assertTrue(self.zoo.add_animal(self.lion_alex))
        self.assertEqual("<Vitaly>: <tiger>, <1>, <180>\n<Alex>: <lion>, <1>, <210>", self.zoo.get_animals())
        self.assertFalse(self.zoo.add_animal(self.hippo_gloria))
        self.assertEqual("<Vitaly>: <tiger>, <1>, <180>\n<Alex>: <lion>, <1>, <210>", self.zoo.get_animals())

    def test_remove_animal(self):
        self.assertTrue(self.zoo.add_animal(self.tiger_vitaly))
        self.assertEqual("<Vitaly>: <tiger>, <1>, <180>", self.zoo.get_animals())
        self.assertTrue(self.zoo.remove_animal(0))
        self.assertEqual("", self.zoo.get_animals())

    def test_is_there_space(self):
        self.assertTrue(self.zoo.is_there_space())

    def test_is_there_space_when_no_space(self):
        self.assertTrue(self.zoo.add_animal("Tiger"))
        self.assertTrue(self.zoo.add_animal("Lion"))
        self.assertFalse(self.zoo.is_there_space())

    def test_get_daily_expenses_when_empty_zoo(self):
        self.assertEqual(0, self.zoo.get_daily_expenses())

    def test_get_daily_expenses(self):
        self.assertTrue(self.zoo.add_animal(self.tiger_vitaly))
        expected = 4 * (self.tiger_vitaly.get_food_weight_ratio() * self.tiger_vitaly.weight)
        self.assertEqual(expected, self.zoo.get_daily_expenses())
Beispiel #47
0
class TestAnimal(unittest.TestCase):
    def setUp(self):
        self.cat_animal = Animal("cat", 365, "Pena", "Female", 5, 5475)

    def test_animal_init(self):
        self.assertEqual("cat", self.cat_animal.species)
        self.assertEqual(365, self.cat_animal.age)
        self.assertEqual("Pena", self.cat_animal.name)
        self.assertEqual("Female", self.cat_animal.gender)
        self.assertEqual(5, self.cat_animal.weight)
        self.assertEqual(5475, self.cat_animal.life_expectancy)

    def test_grow(self):
        self.cat_animal.grow(2, 1)
        self.assertEqual(366, self.cat_animal.age)
        self.assertEqual(7, self.cat_animal.weight)

    def test_eat(self):
        self.cat_animal.eat(2)
        self.assertEqual(7, self.cat_animal.weight)

    def test_dying(self):
        self.assertFalse(self.cat_animal.dying())
Beispiel #48
0
class TestAnimal(unittest.TestCase):
    def setUp(self):
        self.testAnimal = Animal("Tiger", 2, "Name", "Male", 50)
        self.femaleAnimal = Animal('Tiger', 3, 'Penka', "Female", 5)

    def tearDown(self):
        Animal.NAMES = {}

    def test_init(self):
        self.assertEqual(self.testAnimal.species, "Tiger")
        self.assertEqual(self.testAnimal.age, 2)
        self.assertEqual(self.testAnimal.name, "Name")
        self.assertEqual(self.testAnimal.gender, "Male")
        self.assertEqual(self.testAnimal.weight, 50)

    def test_equal_names_raises_error(self):
        with self.assertRaises(NameError):
            self.testAnimal2 = Animal("Tiger", 2, "Name", "Female", 50)

    def test_grow_older(self):
        self.testAnimal.grow()
        self.assertEqual(self.testAnimal.age, 3)

    def test_gestation(self):
        self.femaleAnimal.in_gestation = True
        self.femaleAnimal.grow()
        self.assertEqual(self.femaleAnimal.gestation, 209)

    def test_eating_price_for_carnivore(self):
        result = self.testAnimal.eating_price()
        self.assertEqual(result, 200*0.3)

    def test_eating_price_for_herbivore(self):
        self.testAnimal2 = Animal("Rabbit", 1, "Zaek", "Male", 15)
        result = self.testAnimal2.eating_price()
        self.assertEqual(result, 30*0.1)

    def test_is_dead_when_already_dead(self):
        self.testAnimal.is_alive = False
        result = self.testAnimal.is_dead()
        self.assertTrue(result)

    def test_is_dead_when_not_dead(self):
        result = self.testAnimal.is_dead()
        for i in range(0, 100):
            self.assertIn(result, [True, False])
Beispiel #49
0
 def test_grow(self):
     self.puh_panda.grow(5)
     self.assertEqual(self.puh_panda.age, 25)
     self.assertEqual(self.puh_panda.weight, 101.5)
     self.assertEqual(self.puh_panda.relax_period, 25)
     self.assertEqual(self.puh_panda.gestination_period, 0)
     yana_tiger = Animal("tiger", 5, "Yana", "female", 30)
     yana_tiger.is_pregnant = True
     yana_tiger.grow(5)
     self.assertEqual(yana_tiger.relax_period, 0)
     ivo_tiger = Animal("tiger", 5, "Ivo", "female", 101)
     ivo_tiger.grow(5)
     #cannot get bigger anymore, it is fat enough
     self.assertEqual(ivo_tiger.weight, 101)
Beispiel #50
0
    def test__init(self):
        self.animal = Animal("bear", 14, "Poll 1", 'male', 10.0)
        self.assertEqual("bear", self.animal.species)
        self.assertEqual(14, self.animal.age_in_months)
        self.assertEqual("Poll 1", self.animal.name)
        self.assertEqual('male', self.animal.gender)
        self.assertEqual(10.0, self.animal.kilos_weight)
        self.assertEqual({"bear": ["Poll 1"]}, self.animal.SPECIES_NAMES)

        self.assertEqual({"life_expectancy": 12,
                          "food_type": "meat",
                          "gestation_period": 6,
                          "newborn_weight": 20,
                          "average_weight": 100,
                          "weight_age_ratio": 9,
                          "food_weight_ratio": 0.2},
                         self.animal.json_species_data)
Beispiel #51
0
 def test_grow_tiger(self):
     animal = Animal("tiger", 2, "TegavTiger", "male", 300)
     animal.grow()
     self.assertEqual(animal.age, 3)
     self.assertEqual(animal.weight, 305)
Beispiel #52
0
 def test_eat_panda(self):
     animal = Animal("panda", 1, "Ivo", "male", 300)
     animal.eat()
     self.assertEqual(animal.weight, 300.1)
from animal import Animal

puppy = Animal("Rover", 36, 48, "Brown", "Bark")
puppy.eat()
puppy.sleep()
puppy.run()
puppy.displayAnimalCount()

fish = Animal("Bubbles", 2, 1, "Gold", "blub")
fish.eat()
fish.sleep()
fish.displayAnimalCount()
Beispiel #54
0
 def test_eat_tiger(self):
     animal = Animal("tiger", 2, "TegavTiger", "male", 300)
     animal.eat()
     self.assertEqual(animal.weight, 300.09)
Beispiel #55
0
 def setUp(self):
     self.cat_animal = Animal("cat", 365, "Pena", "Female", 5, 5475)
 def setUp(self):
     self.my_animal = Animal("bear", 5, "puh", "m", 150, 10)
Beispiel #57
0
 def test_eat_bear(self):
     animal = Animal("bear", 2, "MecoPug", "male", 300)
     animal.eat()
     self.assertEqual(animal.weight, 300.06)
Beispiel #58
0
 def test_grow_bear(self):
     animal = Animal("bear", 2, "MecoPug", "male", 300)
     animal.grow()
     self.assertEqual(animal.age, 3)
     self.assertEqual(animal.weight, 305)
from animal import Animal

gerbil = Animal("Spot", 5, 1, "Brown and White", "Squeaks")
gerbil.eat()
gerbil.sleep()
gerbil.run()
Beispiel #60
0
 def test_grow_panda(self):
     animal = Animal("panda", 1, "Ivo", "male", 300)
     animal.grow()
     self.assertEqual(animal.age, 2)
     self.assertEqual(animal.weight, 304)