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