本文整理汇总了Python中animal.Animal.get_age方法的典型用法代码示例。如果您正苦于以下问题:Python Animal.get_age方法的具体用法?Python Animal.get_age怎么用?Python Animal.get_age使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类animal.Animal
的用法示例。
在下文中一共展示了Animal.get_age方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestAnimal
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import get_age [as 别名]
class TestAnimal(unittest.TestCase):
def setUp(self):
self.tiger = Animal('tiggy', 'tiger', 'male', 1, 5)
self.hippo = Animal('hippy', 'hippo', 'female', 1, 50)
def test_get_name(self):
self.assertEqual('tiggy', self.tiger.get_name())
self.assertEqual('hippy', self.hippo.get_name())
def test_get_species(self):
self.assertEqual('tiger', self.tiger.get_species())
self.assertEqual('hippo', self.hippo.get_species())
def test_get_gender(self):
self.assertEqual('male', self.tiger.get_gender())
self.assertEqual('female', self.hippo.get_gender())
def test_get_weight(self):
self.assertEqual(5, self.tiger.get_weight())
self.assertEqual(50, self.hippo.get_weight())
def test_Get_age(self):
self.assertEqual(0, self.tiger.get_age())
self.assertEqual(0, self.hippo.get_age())
def test_grow_by_age(self):
self.tiger.grow(365, cursor)
self.hippo.grow(365, cursor)
self.assertEqual(1, self.tiger.get_age())
self.assertEqual(1, self.hippo.get_age())
def test_grow_by_weight(self):
self.tiger.grow(1*32, cursor)
self.hippo.grow(1*32, cursor)
self.assertEqual(17, int(self.tiger.get_weight()))
self.assertEqual(52, int(self.hippo.get_weight()))
def test_grow_when_average_weight_is_reached(self):
self.tiger.grow(10000, cursor)
self.assertEqual(250, self.tiger.get_weight())
def get_food_type(self):
self.assertEqual('carnivore', self.tiger.get_food_type())
self.assertEqual('herbivore', self.hippo.get_food_type())
def test_get_food_weight_ratio(self):
self.assertEqual(25, self.hippo.get_food_weight_ratio())
self.assertEqual(0.06, self.tiger.get_food_weight_ratio())
def test_eat(self):
self.assertEqual(1.2, self.tiger.eat(1))#amount of food eaten in 1 day
self.assertEqual(2500, self.hippo.eat(1))# hippoes are expensive
def test_get_gestation_period(self):
self.assertEqual(4, self.tiger.get_gestation_period())
self.assertEqual(8, self.hippo.get_gestation_period())
def test_death_when_age_is_above_average(self):
self.tiger.grow(10000, cursor)
self.assertTrue(self.tiger.die())