本文整理汇总了Python中orc.Orc.has_weapon方法的典型用法代码示例。如果您正苦于以下问题:Python Orc.has_weapon方法的具体用法?Python Orc.has_weapon怎么用?Python Orc.has_weapon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类orc.Orc
的用法示例。
在下文中一共展示了Orc.has_weapon方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OrcTest
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc import has_weapon [as 别名]
class OrcTest(unittest.TestCase):
def setUp(self):
self.orc = Orc("Thrall", 200, 1.7)
self.orc.weapon = Weapon("Frostmourne", 35, 0.7)
def test_init(self):
self.assertEqual(self.orc.name, "Thrall")
self.assertEqual(self.orc.health, 200)
self.assertEqual(self.orc.berserk_factor, 1.7)
def test_berserk_set_with_higher_value(self):
result = self.orc.set_berserk_factor(3.5)
self.assertEqual(result, 2.0)
def test_berserk_set_with_lower_value(self):
result = self.orc.set_berserk_factor(0.4)
self.assertEqual(result, 1.0)
def test_berserk_set_with_negative(self):
result = self.orc.set_berserk_factor(-5)
self.assertEqual(result, 1.0)
def test_has_weapon_when_present(self):
self.assertEqual(self.orc.has_weapon(), True)
def test_has_weapon_when_not_present(self):
self.orc.weapon = None
self.assertEqual(self.orc.has_weapon(), False)
def test_equip_stronger_weapon(self):
test_weapon = Weapon("Stick", 500, 0.1)
self.orc.equip_weapon(test_weapon)
self.assertEqual(self.orc.weapon, test_weapon)
def test_equip_weaker_weapon(self):
test_weapon = Weapon("Stick", 5, 0.1)
self.orc.equip_weapon(test_weapon)
self.assertNotEqual(self.orc.weapon, test_weapon)
def test_attack_when_no_weapon_is_equipped(self):
self.orc.weapon = None
self.assertEqual(self.orc.attack(), 0)
def test_attack_when_weapon_is_equipped(self):
self.assertIn(self.orc.attack(), [35 * 1.7, 70 * 1.7])
示例2: EntityTest
# 需要导入模块: from orc import Orc [as 别名]
# 或者: from orc.Orc import has_weapon [as 别名]
class EntityTest(unittest.TestCase):
def setUp(self):
self.shosh_hero = Hero('Shosh', 100, 'GraveRobber')
self.zaithan_orc = Orc('Zaithan', 150, 0.5)
self.destroyer_weapon = Weapon('Destroyer Axe', 30, 0.7)
self.crystal_weapon = Weapon('Crystal Dagger', 15, 0.2)
self.molten_weapon = Weapon('Molten Sword', 27, 0.4)
def test_init(self):
self.assertEqual(self.shosh_hero.name, 'Shosh')
self.assertEqual(self.shosh_hero.health, 100)
self.assertEqual(self.shosh_hero.nickname, 'GraveRobber')
def test_get_health(self):
self.assertEqual(self.shosh_hero.get_health(), 100)
def test_is_alive(self):
self.assertTrue(self.shosh_hero.is_alive())
def test_is_dead(self):
self.shosh_hero.health = 0
self.assertFalse(self.shosh_hero.is_alive())
def test_take_damage_integer_value(self):
self.shosh_hero.take_damage(25)
self.assertEqual(self.shosh_hero.get_health(), 75)
def test_take_damage_decimal_value(self):
self.shosh_hero.take_damage(0.5)
self.assertEqual(self.shosh_hero.get_health(), 99.5)
def test_take_huge_amount_of_damage(self):
self.shosh_hero.take_damage(150)
self.assertEqual(self.shosh_hero.get_health(), 0)
def test_take_huge_amount_of_damage_decimal(self):
self.shosh_hero.take_damage(120.5)
self.assertEqual(self.shosh_hero.get_health(), 0)
def test_take_healing_when_dead(self):
self.shosh_hero.health = 0
self.assertFalse(self.shosh_hero.take_healing(30))
def test_take_hiper_super_big_healing(self):
self.shosh_hero.health = 70
self.assertTrue(self.shosh_hero.take_healing(200))
self.assertEqual(self.shosh_hero.health, self.shosh_hero.get_health())
def test_take_healing(self):
self.shosh_hero.health = 20
self.assertTrue(self.shosh_hero.take_healing(50))
self.assertEqual(self.shosh_hero.health, 70)
def test_has_weapon(self):
self.zaithan_orc.weapon = None
self.shosh_hero.weapon = self.crystal_weapon
self.assertTrue(self.shosh_hero.has_weapon())
self.assertFalse(self.zaithan_orc.has_weapon())
def test_equip_weapon(self):
self.shosh_hero.equip_weapon(self.destroyer_weapon)
self.assertTrue(self.shosh_hero.has_weapon())
self.assertEqual(self.shosh_hero.weapon.type, 'Destroyer Axe')
def test_equip_weapon_and_discard_the_old_one(self):
self.assertFalse(self.zaithan_orc.has_weapon())
self.zaithan_orc.equip_weapon(self.crystal_weapon)
self.assertTrue(self.zaithan_orc.has_weapon())
self.assertEqual(self.zaithan_orc.weapon.type, 'Crystal Dagger')
self.zaithan_orc.equip_weapon(self.molten_weapon)
self.assertTrue(self.zaithan_orc.has_weapon())
self.assertNotEqual(self.zaithan_orc.weapon.type, 'Crystal Dagger')
self.assertEqual(self.zaithan_orc.weapon.type, 'Molten Sword')
def test_attack_without_weapon(self):
self.assertEqual(self.shosh_hero.attack(), 0)
def test_attack_with_weapon(self):
self.shosh_hero.equip_weapon(self.destroyer_weapon)
self.assertIn(self.shosh_hero.attack(), [30, 60])