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