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


Python Monster.heal方法代码示例

本文整理汇总了Python中monster.Monster.heal方法的典型用法代码示例。如果您正苦于以下问题:Python Monster.heal方法的具体用法?Python Monster.heal怎么用?Python Monster.heal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在monster.Monster的用法示例。


在下文中一共展示了Monster.heal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: HealTest

# 需要导入模块: from monster import Monster [as 别名]
# 或者: from monster.Monster import heal [as 别名]
class HealTest(unittest.TestCase):
    """Test the functionality of the Monster class heal function."""

    def setUp(self):
        self.new_monster = Monster("Cookie")

    def tearDown(self):
        del self.new_monster

    def test_heal_health_gt_10(self):
        """
        Call the heal method with 6 to add to the initial value of 10.
        Check that the health attribute remains unchanged.
        """

        health = self.new_monster.health

        # Call function
        self.new_monster.heal(6)

        self.assertEqual(health, self.new_monster.health)

    def test_heal_health_le_10(self):
        """
        Set health to 2. Call the heal method with 6 to add.
        Check that the health attribute changes to 8.
        """

        self.new_monster.health = 2

        # Call function
        self.new_monster.heal(6)

        self.assertEqual(self.new_monster.health, 8)

    def test_heal_negative_health_le_10(self):
        """
        Call the heal method with -6 to add.
        Check that the health attribute changes to 4.
        """

        # Call function
        self.new_monster.heal(-6)

        self.assertEqual(4, self.new_monster.health)

    def test_heal_negative_health_lt_0(self):
        """
        Call the heal method with -16 to add.
        Check that the health attribute changes to -6.
        """

        # Call function
        self.new_monster.heal(-16)

        self.assertEqual(-6, self.new_monster.health)
开发者ID:PDXDevCampJuly,项目名称:atifar,代码行数:58,代码来源:test_heal.py

示例2: test_heal

# 需要导入模块: from monster import Monster [as 别名]
# 或者: from monster.Monster import heal [as 别名]
class test_heal(unittest.TestCase):
    def setUp(self):
        self.monsta = Monster()
        self.monsta.health = 5

    #Tests if monster heals
    def test_valid_heal(self):
        health = self.monsta.heal(5)

        self.assertEqual(health, 10, "Heal did not work")

    #Monster should not heal if sum > 10
    def test_invalid_heal(self):
        health = self.monsta.heal(6)

        self.assertNotEqual(health, 11, "Heal should not have worked")

    #Tests invalid output
    @patch ('sys.stdout', new_callable=StringIO)
    def test_attack_die_KO(self, mock_stdout):
        health = self.monsta.attack(6)

        text = "Invalid heal amount"
        self.assertNotEqual(mock_stdout.getValue(), text)
开发者ID:TheOneTAR,项目名称:daniel_pearl,代码行数:26,代码来源:test_heal.py


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