本文整理汇总了Python中fight.Fight.coin_toss方法的典型用法代码示例。如果您正苦于以下问题:Python Fight.coin_toss方法的具体用法?Python Fight.coin_toss怎么用?Python Fight.coin_toss使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fight.Fight
的用法示例。
在下文中一共展示了Fight.coin_toss方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FightTest
# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import coin_toss [as 别名]
class FightTest(unittest.TestCase):
def setUp(self):
self.hero = Hero("Arthas", 660, "Lich King")
self.orc = Orc("Thrall", 700, 1.7)
self.heroWeapon = Weapon("Frostmourne", 35, 0.7)
self.orcWeapon = Weapon("Doomhammer", 40, 0.6)
self.hero.weapon = self.heroWeapon
self.orc.weapon = self.orcWeapon
self.fight = Fight(self.hero, self.orc)
def test_init(self):
self.assertEqual(self.fight.hero, self.hero)
self.assertEqual(self.fight.orc, self.orc)
def test_coin_toss_for_first_attacker(self):
self.assertIn(self.fight.coin_toss(),
[(self.orc, self.hero), (self.hero, self.orc)])
def test_simulate_fight_with_no_weapons(self):
self.fight.hero.weapon = None
self.fight.orc.weapon = None
result = self.fight.simulate_fight()
self.assertEqual(result, "No winner")
def test_simulate_fight_with_only_one_weapon(self):
self.fight.hero.weapon = None
result = self.fight.simulate_fight()
self.assertEqual(result, self.fight.orc)
def test_simulate_fight_with_both_armed_chars(self):
result = self.fight.simulate_fight()
self.assertIn(result, [self.fight.orc, self.hero])