本文整理汇总了Python中animal.Animal.die方法的典型用法代码示例。如果您正苦于以下问题:Python Animal.die方法的具体用法?Python Animal.die怎么用?Python Animal.die使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类animal.Animal
的用法示例。
在下文中一共展示了Animal.die方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestAnimal
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import die [as 别名]
class TestAnimal(unittest.TestCase):
def setUp(self):
self.animal = Animal("tiger", 10, "Tig", "male", 175)
def test_properties(self):
self.assertEqual(self.animal.specie, "tiger")
self.assertEqual(self.animal.age, 10)
self.assertEqual(self.animal.name, "Tig")
self.assertEqual(self.animal.gender, "male")
self.assertEqual(self.animal.weight, 175)
def test_grow(self):
self.animal.grow(250, 15.1)
self.assertEqual(11, self.animal.age)
self.assertEqual(190.1, self.animal.weight)
def test_grow_again(self):
self.animal.grow(175, 2)
self.assertEqual(11, self.animal.age)
self.assertEqual(175, self.animal.weight)
def test_eat(self):
self.assertEqual(17.5, self.animal.eat(0.1))
def test_die(self):
is_dead = self.animal.die(3)
self.assertEqual(False, is_dead)
示例2: AnimalTests
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import die [as 别名]
class AnimalTests(unittest.TestCase):
def setUp(self):
self.animal = Animal("tiger", 144, "DiviaLud", "male", 300)
def test_init(self):
self.assertEqual(self.animal.species, "tiger")
self.assertEqual(self.animal.age, 144)
self.assertEqual(self.animal.name, "DiviaLud")
self.assertEqual(self.animal.gender, "male")
self.assertEqual(self.animal.weight, 300)
def test_grow(self):
self.animal.grow(2, 50)
self.assertEqual(self.animal.age, 146)
self.assertEqual(self.animal.weight, 350)
def test_eat_meat(self):
self.animal.eat("meat", 4)
self.assertGreater(self.animal.weight, 12)
self.assertEqual(self.animal.meat_eaten, 4)
#self.assertEqual(self.animal.Zoo.available_meat, 296)
self.animal.eat("meat", 4)
self.assertGreater(self.animal.weight, 16)
self.assertEqual(self.animal.meat_eaten, 8)
#self.assertEqual(self.animal.Zoo.available_meat, 292)
def test_eat_grass(self):
self.animal.eat("grass", 4)
self.assertGreater(self.animal.weight, 12)
self.assertEqual(self.animal.grass_eaten, 4)
#self.assertEqual(self.animal.Zoo.available_grass, 196)
self.animal.eat("grass", 4)
self.assertGreater(self.animal.weight, 16)
self.assertEqual(self.animal.grass_eaten, 8)
#self.assertEqual(self.animal.Zoo.available_grass, 192)
def test_die(self):
died_or_not = []
for i in range(100):
died_or_not.append(self.animal.die(180))
self.assertIn(True, died_or_not)
self.assertIn(False, died_or_not)
示例3: TestAnimal
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import die [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())