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


Python Fight._flip_coin方法代码示例

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


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

示例1: Test_Fight

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import _flip_coin [as 别名]
class Test_Fight(unittest.TestCase):
    def setUp(self):
        self.orc = Orc("orc", 90, 1.4)
        self.hero = Hero("hero", 100, "DragonSlayer")
        self.hero.equip_weapon(Weapon("Mighty Axe", 25, 0.2))
        self.orc.equip_weapon(Weapon("basher", 16, 0.75))
        self.fight = Fight(self.hero, self.orc)

    def test_fight_init(self):
        self.assertEqual(self.fight.orc, self.orc)
        self.assertEqual(self.fight.hero, self.hero)

    def test_simulate_fight(self):
        self.fight.simulate_fight()
        self.assertTrue(self.orc.health == 0 or self.hero.health == 0)

    def test_flip_coin(self):
        results = set()
        for i in range(100):
            results.add(self.fight._flip_coin())
        self.assertEqual(len(results), 2)
开发者ID:svetlio2,项目名称:hackbg,代码行数:23,代码来源:fight_test.py

示例2: TestFight

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import _flip_coin [as 别名]
class TestFight(unittest.TestCase):

    def setUp(self):
        self.orc = Orc("Bron", 300, 1.3)
        self.hero = Hero("Brom", 300, "DragonSlayer")
        self.fight_sim = Fight(self.hero, self.orc)

    def test_hero_in_fight(self):
        self.assertEqual("Brom", self.fight_sim.hero.name)
        self.assertEqual(300, self.fight_sim.hero.health)
        self.assertEqual("DragonSlayer", self.fight_sim.hero.nickname)

    def test_orc_in_fight(self):
        self.assertEqual("Bron", self.fight_sim.orc.name)
        self.assertEqual(300, self.fight_sim.orc.health)
        self.assertEqual(1.3, self.fight_sim.orc.berserk_factor)

    def test_flip_coin(self):
        coins = []
        for i in range(100):
            coins.append(self.fight_sim._flip_coin())
        self.assertIn(self.fight_sim._HERO_TURN, coins)
        self.assertIn(self.fight_sim._ORC_TURN, coins)

    def test_simulate_fight_orc_win(self):
        orc_w = Orc("Winner", 300, 2)
        hero_l = Hero("Loser", 300, "TheLoser")
        wep = Weapon("Ubiec", 15, 0.5)
        orc_w.equip_weapon(wep)
        orc_fight = Fight(hero_l, orc_w)
        self.assertEqual(orc_fight.simulate_fight(), orc_fight._ORC_WINNER)

    def test_simulate_fight_hero_win(self):
        orc_l = Orc("Loser", 300, 2)
        hero_w = Hero("Winner", 300, "TheWinner")
        wep = Weapon("Ubiec", 15, 0.5)
        hero_w.equip_weapon(wep)
        hero_fight = Fight(hero_w, orc_l)
        self.assertEqual(hero_fight.simulate_fight(), hero_fight._HERO_WINNER)
开发者ID:SlaviSotirov,项目名称:HackBulgaria,代码行数:41,代码来源:fight_test.py


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