当前位置: 首页>>代码示例>>Python>>正文


Python Animal.is_dead方法代码示例

本文整理汇总了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)
开发者ID:monnn,项目名称:Zoo-Problem,代码行数:28,代码来源:test_animal.py

示例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])
开发者ID:stoyaneft,项目名称:Zoo,代码行数:48,代码来源:animal_test.py


注:本文中的animal.Animal.is_dead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。