当前位置: 首页>>代码示例>>Python>>正文


Python animal.Animal类代码示例

本文整理汇总了Python中animal.Animal的典型用法代码示例。如果您正苦于以下问题:Python Animal类的具体用法?Python Animal怎么用?Python Animal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Animal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestAnimal

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)
开发者ID:monnn,项目名称:Zoo-Problem,代码行数:26,代码来源:test_animal.py

示例2: TestAnimal

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)
开发者ID:skdls-,项目名称:Zoo_Srolev_Istoilov,代码行数:26,代码来源:test_animal.py

示例3: test_actions_with_pregnant_one

 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)
开发者ID:mihail-nikolov,项目名称:hackBG,代码行数:8,代码来源:zoo_test.py

示例4: test_make_reproduction_moves_false2_one_couple

 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)
开发者ID:mihail-nikolov,项目名称:hackBG,代码行数:9,代码来源:zoo_test.py

示例5: test_actions_with_pregnant_one_new_baby

 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)
开发者ID:mihail-nikolov,项目名称:hackBG,代码行数:10,代码来源:zoo_test.py

示例6: __init__

    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 = []
开发者ID:rikel,项目名称:sheepherding,代码行数:10,代码来源:dog.py

示例7: insert_animal

 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
     ))
开发者ID:vberger,项目名称:evolving-project,代码行数:13,代码来源:__init__.py

示例8: test_pregnancy_simulated_time_pregnant_female

 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)
开发者ID:modzozo,项目名称:Zoo,代码行数:7,代码来源:animal_test.py

示例9: TestZoo

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])
开发者ID:JusttRelaxx,项目名称:Zoo,代码行数:34,代码来源:zoo_test.py

示例10: reproduce

    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
开发者ID:dionisos2,项目名称:evolve,代码行数:17,代码来源:generation_manager.py

示例11: AnimalTests

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)
开发者ID:NikiMaslarski,项目名称:Zoo,代码行数:18,代码来源:animal_tests.py

示例12: reproduce

    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"
开发者ID:emilenovv,项目名称:ZooTeamwork,代码行数:21,代码来源:zoo.py

示例13: Animal_test

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)
开发者ID:AlexanderTankov,项目名称:HackBulgaria-Programming-101,代码行数:33,代码来源:animal_test.py

示例14: TestAnimal

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)
开发者ID:kristiyankisimov,项目名称:Zoo,代码行数:27,代码来源:tests_animal.py

示例15: TestAnimal

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)
开发者ID:dsspasov,项目名称:ZOO,代码行数:27,代码来源:animal_test.py


注:本文中的animal.Animal类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。