本文整理汇总了Python中animal.Animal._chance_of_dying方法的典型用法代码示例。如果您正苦于以下问题:Python Animal._chance_of_dying方法的具体用法?Python Animal._chance_of_dying怎么用?Python Animal._chance_of_dying使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类animal.Animal
的用法示例。
在下文中一共展示了Animal._chance_of_dying方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Animal_test
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import _chance_of_dying [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)