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


Python Animal.die方法代码示例

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


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

示例1: TestAnimal

# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import die [as 别名]
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,代码行数:29,代码来源:tests_animal.py

示例2: AnimalTests

# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import die [as 别名]
class AnimalTests(unittest.TestCase):

    def setUp(self):
        self.animal = Animal("tiger", 144, "DiviaLud", "male", 300)

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

    def test_grow(self):
        self.animal.grow(2, 50)
        self.assertEqual(self.animal.age, 146)
        self.assertEqual(self.animal.weight, 350)

    def test_eat_meat(self):
        self.animal.eat("meat", 4)
        self.assertGreater(self.animal.weight, 12)
        self.assertEqual(self.animal.meat_eaten, 4)
        #self.assertEqual(self.animal.Zoo.available_meat, 296)

        self.animal.eat("meat", 4)
        self.assertGreater(self.animal.weight, 16)
        self.assertEqual(self.animal.meat_eaten, 8)
        #self.assertEqual(self.animal.Zoo.available_meat, 292)

    def test_eat_grass(self):
        self.animal.eat("grass", 4)
        self.assertGreater(self.animal.weight, 12)
        self.assertEqual(self.animal.grass_eaten, 4)
        #self.assertEqual(self.animal.Zoo.available_grass, 196)

        self.animal.eat("grass", 4)
        self.assertGreater(self.animal.weight, 16)
        self.assertEqual(self.animal.grass_eaten, 8)
        #self.assertEqual(self.animal.Zoo.available_grass, 192)

    def test_die(self):
        died_or_not = []
        for i in range(100):
            died_or_not.append(self.animal.die(180))
        self.assertIn(True, died_or_not)
        self.assertIn(False, died_or_not)
开发者ID:emilenovv,项目名称:ZooTeamwork,代码行数:47,代码来源:animal_class_tests.py

示例3: TestAnimal

# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import die [as 别名]
class TestAnimal(unittest.TestCase):

    def setUp(self):
        self.tiger = Animal('tiggy', 'tiger', 'male', 1, 5)
        self.hippo = Animal('hippy', 'hippo', 'female', 1, 50)

    def test_get_name(self):
        self.assertEqual('tiggy', self.tiger.get_name())
        self.assertEqual('hippy', self.hippo.get_name())

    def test_get_species(self):
        self.assertEqual('tiger', self.tiger.get_species())
        self.assertEqual('hippo', self.hippo.get_species())

    def test_get_gender(self):
        self.assertEqual('male', self.tiger.get_gender())
        self.assertEqual('female', self.hippo.get_gender())

    def test_get_weight(self):
        self.assertEqual(5, self.tiger.get_weight())
        self.assertEqual(50, self.hippo.get_weight())

    def test_Get_age(self):
        self.assertEqual(0, self.tiger.get_age())
        self.assertEqual(0, self.hippo.get_age())

    def test_grow_by_age(self):
        self.tiger.grow(365, cursor)
        self.hippo.grow(365, cursor)
        self.assertEqual(1, self.tiger.get_age())
        self.assertEqual(1, self.hippo.get_age())

    def test_grow_by_weight(self):
        self.tiger.grow(1*32, cursor)
        self.hippo.grow(1*32, cursor)
        self.assertEqual(17, int(self.tiger.get_weight()))
        self.assertEqual(52, int(self.hippo.get_weight()))

    def test_grow_when_average_weight_is_reached(self):
        self.tiger.grow(10000, cursor)
        self.assertEqual(250, self.tiger.get_weight())

    def get_food_type(self):
        self.assertEqual('carnivore', self.tiger.get_food_type())
        self.assertEqual('herbivore', self.hippo.get_food_type())

    def test_get_food_weight_ratio(self):
        self.assertEqual(25, self.hippo.get_food_weight_ratio())
        self.assertEqual(0.06, self.tiger.get_food_weight_ratio())

    def test_eat(self):
        self.assertEqual(1.2, self.tiger.eat(1))#amount of food eaten in 1 day
        self.assertEqual(2500, self.hippo.eat(1))# hippoes are expensive

    def test_get_gestation_period(self):
        self.assertEqual(4, self.tiger.get_gestation_period())
        self.assertEqual(8, self.hippo.get_gestation_period())

    def test_death_when_age_is_above_average(self):
        self.tiger.grow(10000, cursor)
        self.assertTrue(self.tiger.die())
开发者ID:MilenMMinev,项目名称:Zoo,代码行数:63,代码来源:animal_tests.py


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