本文整理汇总了Python中animal.Animal.get_food_weight_ratio方法的典型用法代码示例。如果您正苦于以下问题:Python Animal.get_food_weight_ratio方法的具体用法?Python Animal.get_food_weight_ratio怎么用?Python Animal.get_food_weight_ratio使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类animal.Animal
的用法示例。
在下文中一共展示了Animal.get_food_weight_ratio方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ZooTests
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import get_food_weight_ratio [as 别名]
class ZooTests(unittest.TestCase):
def setUp(self):
self.zoo = Zoo("Alexandria Zoo", 2, 1000)
self.tiger_vitaly = Animal("tiger", 1, "Vitaly", "male", 180)
self.lion_alex = Animal("lion", 1, "Alex", "male", 210)
self.hippo_gloria = Animal("hippo", 2, "Gloria", "female", 1600)
def test_get_zoo_name(self):
self.assertEqual("Alexandria Zoo", self.zoo.get_name())
def test_get_zoo_max_capacity(self):
self.assertEqual(2, self.zoo.get_max_capacity())
def test_get_zoo_budget(self):
self.assertEqual(1000, self.zoo.get_budget())
def test_get_animals(self):
self.assertEqual("", self.zoo.get_animals())
def test_add_animal(self):
self.assertTrue(self.zoo.add_animal(self.tiger_vitaly))
self.assertEqual("<Vitaly>: <tiger>, <1>, <180>", self.zoo.get_animals())
def test_add_animal_when_no_space(self):
self.assertTrue(self.zoo.add_animal(self.tiger_vitaly))
self.assertEqual("<Vitaly>: <tiger>, <1>, <180>", self.zoo.get_animals())
self.assertTrue(self.zoo.add_animal(self.lion_alex))
self.assertEqual("<Vitaly>: <tiger>, <1>, <180>\n<Alex>: <lion>, <1>, <210>", self.zoo.get_animals())
self.assertFalse(self.zoo.add_animal(self.hippo_gloria))
self.assertEqual("<Vitaly>: <tiger>, <1>, <180>\n<Alex>: <lion>, <1>, <210>", self.zoo.get_animals())
def test_remove_animal(self):
self.assertTrue(self.zoo.add_animal(self.tiger_vitaly))
self.assertEqual("<Vitaly>: <tiger>, <1>, <180>", self.zoo.get_animals())
self.assertTrue(self.zoo.remove_animal(0))
self.assertEqual("", self.zoo.get_animals())
def test_is_there_space(self):
self.assertTrue(self.zoo.is_there_space())
def test_is_there_space_when_no_space(self):
self.assertTrue(self.zoo.add_animal("Tiger"))
self.assertTrue(self.zoo.add_animal("Lion"))
self.assertFalse(self.zoo.is_there_space())
def test_get_daily_expenses_when_empty_zoo(self):
self.assertEqual(0, self.zoo.get_daily_expenses())
def test_get_daily_expenses(self):
self.assertTrue(self.zoo.add_animal(self.tiger_vitaly))
expected = 4 * (self.tiger_vitaly.get_food_weight_ratio() * self.tiger_vitaly.weight)
self.assertEqual(expected, self.zoo.get_daily_expenses())
示例2: TestAnimal
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import get_food_weight_ratio [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())