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


Python Animal.try_die方法代码示例

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


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

示例1: Animal_test

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

    def setUp(self):
        self.puh_panda = Animal("panda", 20, "Puh", "male", 100)

    def test_init_animal(self):
        self.assertEqual(self.puh_panda.species, "panda")
        self.assertEqual(self.puh_panda.age, 20)
        self.assertEqual(self.puh_panda.name, "Puh")
        self.assertEqual(self.puh_panda.gender, "male")
        self.assertEqual(self.puh_panda.weight, 100)

    def test_chance_of_dying(self):
        chance = self.puh_panda._chance_of_dying()
        life_expectancy = self.puh_panda.species_info['life_expectancy']
        age = self.puh_panda.age
        self.assertEqual(chance, age / life_expectancy)

    def test_try_die(self):
        results = []
        life_expectancy = self.puh_panda.species_info['life_expectancy']
        # making sure the chance is average
        self.puh_panda.age = life_expectancy // 2

        for i in range(0, 100):
            results.append(self.puh_panda.try_die())

        self.assertTrue(False in results)
        self.assertTrue(True in results)

    def test_try_cannot_die_twice(self):
        results = []
        life_expectancy = self.puh_panda.species_info['life_expectancy']
        # making sure the chance is average
        self.puh_panda.age = life_expectancy // 2
        for i in range(0, 100):
            results.append(self.puh_panda.try_die())

        self.assertEqual(results.count(True), 1)

    def test_eat(self):
        self.assertEqual(self.puh_panda.eat(), 60)

    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)

    def test_get_pregnant(self):
        self.puh_panda.get_pregnant()
        self.assertTrue(self.puh_panda.is_pregnant)
        self.assertEqual(self.puh_panda.gestination_period, 0)
        self.assertEqual(self.puh_panda.relax_period, 0)
开发者ID:mihail-nikolov,项目名称:hackBG,代码行数:65,代码来源:animal_test.py


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