本文整理汇总了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)
示例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)