def init_first_generation(nb_animals: List) -> Dict:
        """ Initialisation de la première génération des animaux """
        """ Création des chiens """
        dogs = []
        for i in range(0, int(nb_animals[0])):
            dogs.append(Dog(True))
        """ Création des singes """
        monkeys = []
        for i in range(0, int(nb_animals[1])):
            monkeys.append(Monkey(True))
        """ Création des souris """
        mouses = []
        for i in range(0, int(nb_animals[2])):
            mouses.append(Mouse(True))
        """ Création des sepents """
        snakes = []
        for i in range(0, int(nb_animals[3])):
            snakes.append(Snake(True))
        """ Rassemblement de l'ensemble des espèces """

        animals = {
            "Dogs": dogs,
            "Mouses": mouses,
            "Monkeys": monkeys,
            "Snakes": snakes
        }

        return animals
Beispiel #2
0
 def test_two_dogs_runing(self):
     start_energy_2nd_dog = 40
     dog_2 = Dog("Dog 2", start_energy_2nd_dog)
     energy_level_1st_dog = self.dog.get_energy()
     energy_level_2nd_dog = dog_2.get_energy()
     wasted_energy = self.dog.run_behavior.wasted_energy
     energy_level_1st_dog -= wasted_energy
     energy_level_2nd_dog -= wasted_energy
     self.dog.run()
     dog_2.run()
     energy_level_after_run_1st_dog = self.dog.get_energy()
     energy_level_after_run_2nd_dog = dog_2.get_energy()
     self.assertEqual(
         energy_level_after_run_1st_dog,
         energy_level_1st_dog,
     )
     self.assertEqual(
         energy_level_after_run_2nd_dog,
         energy_level_2nd_dog,
     )
Beispiel #3
0
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from animals.dog import Dog

dog = Dog()
print dog.speak()
Beispiel #4
0
from zoo.animal import Animal
from animals.dog import Dog


class Cat(Animal):
    def meow(self):
        return 'meowking..'


animal = Animal()
print(animal.eat())

dog = Dog()
print(dog.bark())
print(dog.eat())

cat = Cat()
print(cat.meow())
print(cat.eat())
Beispiel #5
0
from animals.cat import Cat
from animals.dog import Dog
from animals.kitten import Kitten
from animals.tomcat import Tomcat

dog = Dog("Yarik", 3, "Male")
print(dog.make_sound())
print(dog.__repr__())

cat = Cat("Pisana", 2, "Female")
print(cat.make_sound())
print(cat.__repr__())

kitty = Kitten("Miss", 3)
print(kitty.make_sound())
print(kitty.__repr__())

tom = Tomcat("Tom", 5)
print(tom.make_sound())
print(tom.__repr__())
Beispiel #6
0
from animals.dog import Dog

if __name__ == "__main__":
    bruno = Dog("bruno", 4, True)
    bruno.bark()

    bruno.eat()
    bruno.walk()
    def crossover(self, alpha, animal) -> Animal:
        """ Création des nouveaux gènes en associant 50% du gène père et 50% du gène mère """

        new_animal = None
        if alpha.name == "Dogs":
            new_animal = Dog()
        elif alpha.name == "Monkeys":
            new_animal = Monkey()
        elif alpha.name == "Mouses":
            new_animal = Mouse()
        elif alpha.name == "Snakes":
            new_animal = Snake()

        new_animal.meal_need = random.sample(
            alpha.meal_need, 50) + random.sample(animal.meal_need, 50)
        new_animal.vegetable_need = random.sample(
            alpha.vegetable_need, 50) + random.sample(animal.vegetable_need,
                                                      50)
        new_animal.water_need = random.sample(
            alpha.water_need, 50) + random.sample(animal.water_need, 50)
        new_animal.cold_resistance = random.sample(
            alpha.cold_resistance, 50) + random.sample(animal.cold_resistance,
                                                       50)
        new_animal.heat_resistance = random.sample(
            alpha.heat_resistance, 50) + random.sample(animal.heat_resistance,
                                                       50)
        new_animal.aggressiveness = random.sample(
            alpha.aggressiveness, 50) + random.sample(animal.aggressiveness,
                                                      50)
        new_animal.predator_resistance = random.sample(
            alpha.predator_resistance, 50) + random.sample(
                animal.predator_resistance, 50)

        return new_animal
from animals.dog import Dog

barney = Dog("Barney")
tex = Dog("Tex")
barney.bark()
tex.bark()
Beispiel #9
0
 def setUp(self):
     self.dog = Dog("Dog")
Beispiel #10
0
class DogTestCase(unittest.TestCase):
    def setUp(self):
        self.dog = Dog("Dog")

    def test_start_dog_energy_level(self):
        energy_level = self.dog.get_energy()
        self.assertEqual(energy_level, DOG_ENERGY)

    def test_dog_run(self):
        energy_level = self.dog.get_energy()
        wasted_energy = self.dog.run_behavior.wasted_energy
        energy_level -= wasted_energy
        self.dog.run()
        energy_level_after_run = self.dog.get_energy()
        self.assertEqual(energy_level, energy_level_after_run)

    def test_dog_tired_after_run(self):
        running_times = 30  # Any big enough number
        for _ in range(running_times):
            self.dog.run()
        energy_level = self.dog.get_energy()
        self.assertGreaterEqual(energy_level, 0)

    def test_dog_swim(self):
        energy_level = self.dog.get_energy()
        wasted_energy = self.dog.swim_behavior.wasted_energy
        energy_level -= wasted_energy
        self.dog.swim()
        energy_level_after_swim = self.dog.get_energy()
        self.assertEqual(energy_level, energy_level_after_swim)

    def test_dog_tired_after_swim(self):
        running_times = 50  # Any big enough number
        for _ in range(running_times):
            self.dog.swim()
        energy_level = self.dog.get_energy()
        self.assertGreaterEqual(energy_level, 0)

    def test_dog_fly(self):
        energy_level = self.dog.get_energy()
        flying_times = 30  # Any big enough number
        for _ in range(flying_times):
            self.dog.fly()
        energy_level_after_fly = self.dog.get_energy()
        self.assertEqual(energy_level, energy_level_after_fly)

    def test_two_dogs_runing(self):
        start_energy_2nd_dog = 40
        dog_2 = Dog("Dog 2", start_energy_2nd_dog)
        energy_level_1st_dog = self.dog.get_energy()
        energy_level_2nd_dog = dog_2.get_energy()
        wasted_energy = self.dog.run_behavior.wasted_energy
        energy_level_1st_dog -= wasted_energy
        energy_level_2nd_dog -= wasted_energy
        self.dog.run()
        dog_2.run()
        energy_level_after_run_1st_dog = self.dog.get_energy()
        energy_level_after_run_2nd_dog = dog_2.get_energy()
        self.assertEqual(
            energy_level_after_run_1st_dog,
            energy_level_1st_dog,
        )
        self.assertEqual(
            energy_level_after_run_2nd_dog,
            energy_level_2nd_dog,
        )