本文整理汇总了Python中animal.Animal.is_dead方法的典型用法代码示例。如果您正苦于以下问题:Python Animal.is_dead方法的具体用法?Python Animal.is_dead怎么用?Python Animal.is_dead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类animal.Animal
的用法示例。
在下文中一共展示了Animal.is_dead方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestAnimal
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import is_dead [as 别名]
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)
示例2: TestAnimal
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import is_dead [as 别名]
class TestAnimal(unittest.TestCase):
def setUp(self):
self.testAnimal = Animal("Tiger", 2, "Name", "Male", 50)
self.femaleAnimal = Animal('Tiger', 3, 'Penka', "Female", 5)
def tearDown(self):
Animal.NAMES = {}
def test_init(self):
self.assertEqual(self.testAnimal.species, "Tiger")
self.assertEqual(self.testAnimal.age, 2)
self.assertEqual(self.testAnimal.name, "Name")
self.assertEqual(self.testAnimal.gender, "Male")
self.assertEqual(self.testAnimal.weight, 50)
def test_equal_names_raises_error(self):
with self.assertRaises(NameError):
self.testAnimal2 = Animal("Tiger", 2, "Name", "Female", 50)
def test_grow_older(self):
self.testAnimal.grow()
self.assertEqual(self.testAnimal.age, 3)
def test_gestation(self):
self.femaleAnimal.in_gestation = True
self.femaleAnimal.grow()
self.assertEqual(self.femaleAnimal.gestation, 209)
def test_eating_price_for_carnivore(self):
result = self.testAnimal.eating_price()
self.assertEqual(result, 200*0.3)
def test_eating_price_for_herbivore(self):
self.testAnimal2 = Animal("Rabbit", 1, "Zaek", "Male", 15)
result = self.testAnimal2.eating_price()
self.assertEqual(result, 30*0.1)
def test_is_dead_when_already_dead(self):
self.testAnimal.is_alive = False
result = self.testAnimal.is_dead()
self.assertTrue(result)
def test_is_dead_when_not_dead(self):
result = self.testAnimal.is_dead()
for i in range(0, 100):
self.assertIn(result, [True, False])