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


Python Species.is_attackable方法代码示例

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


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

示例1: TestSpecies

# 需要导入模块: from species import Species [as 别名]
# 或者: from species.Species import is_attackable [as 别名]
class TestSpecies(unittest.TestCase):

    def setUp(self):
        self.attacker = Species()
        self.attacker.traits = [TraitCard("carnivore")]
        self.defender = Species()
        self.left_neighbor = Species()
        self.right_neighbor = Species()

        self.species_1 = Species(4, 4, 4)
        self.species_2 = Species(4, 4, 4)
        self.species_3 = Species(4, 4, 3)
        self.species_4 = Species(4, 3, 3)
        self.species_5 = Species(3, 3, 3)
        self.species_list = [self.species_2, self.species_4, self.species_3, self.species_5, self.species_1]


    def test_can_eat(self):
        self.assertFalse(self.species_1.can_eat())
        self.assertTrue(self.species_4.can_eat())
        fat_tissue = Species(4, 3, 4, [TraitCard("fat-tissue")], 3)
        self.assertTrue(fat_tissue.can_eat())
        fat_tissue.fat_storage = 4
        self.assertFalse(fat_tissue.can_eat())

    def test_trait_names(self):
        self.assertEqual(self.defender.trait_names(), [])
        self.assertEqual(self.attacker.trait_names(), ["carnivore"])

    def test_attackable(self):
        self.assertTrue(self.defender.is_attackable(self.attacker))

    def test_no_carnivore(self):
        self.attacker.traits = []
        self.assertFalse(self.defender.is_attackable(self.attacker))

    def test_burrowing(self):
        self.defender.traits = [TraitCard("burrowing")]
        self.defender.population, self.defender.food = (4, 4)
        self.assertFalse(self.defender.is_attackable(self.attacker))
        self.defender.food = 3
        self.assertTrue(self.defender.is_attackable(self.attacker))

    def test_climbing(self):
        self.defender.traits = [TraitCard("climbing")]
        self.assertFalse(self.defender.is_attackable(self.attacker))
        self.attacker.traits.append(TraitCard("climbing"))
        self.assertTrue(self.defender.is_attackable(self.attacker))

    def test_hard_shell(self):
        self.defender.traits = [TraitCard("hard-shell")]
        self.defender.body = 3
        self.attacker.body = 6
        self.assertFalse(self.defender.is_attackable(self.attacker))
        self.attacker.body = 7
        self.assertTrue(self.defender.is_attackable(self.attacker))

    def test_herding(self):
        self.defender.traits = [TraitCard("herding")]
        self.defender.population = 4
        self.attacker.population = 3
        self.assertFalse(self.defender.is_attackable(self.attacker))
        self.attacker.population = 5
        self.assertTrue(self.defender.is_attackable(self.attacker))

    def test_symbiosis(self):
        self.defender.traits = [TraitCard("symbiosis")]
        self.defender.body = 3
        self.right_neighbor.body = 5
        self.assertFalse(self.defender.is_attackable(self.attacker, right_neighbor=self.right_neighbor))
        self.right_neighbor.body = 2
        self.assertTrue(self.defender.is_attackable(self.attacker, right_neighbor=self.right_neighbor))

    def test_warning_call(self):
        self.left_neighbor.traits = [TraitCard("warning-call")]
        self.right_neighbor.traits = [TraitCard("warning-call")]
        self.assertFalse(self.defender.is_attackable(self.attacker, left_neighbor=self.left_neighbor))
        self.assertFalse(self.defender.is_attackable(self.attacker, right_neighbor=self.right_neighbor))
        self.attacker.traits.append(TraitCard("ambush"))
        self.assertTrue(self.defender.is_attackable(self.attacker, left_neighbor=self.left_neighbor))

    def test_is_larger(self):
        # Population different
        self.defender.population = 2
        self.attacker.population = 1
        self.assertEqual(Species.is_larger(self.defender, self.attacker), 1)
        self.assertEqual(Species.is_larger(self.attacker, self.defender), -1)
        # Same population different food
        self.attacker.population = 2
        self.defender.food = 2
        self.attacker.food = 1
        self.assertEqual(Species.is_larger(self.defender, self.attacker), 1)
        self.assertEqual(Species.is_larger(self.attacker, self.defender), -1)
        # Same population and food different body
        self.attacker.food = 2
        self.defender.body = 4
        self.attacker.body = 3
        self.assertEqual(Species.is_larger(self.defender, self.attacker), 1)
        self.assertEqual(Species.is_larger(self.attacker, self.defender), -1)
        # Equal population, food, and body
#.........这里部分代码省略.........
开发者ID:lydiaauch,项目名称:software-dev-2016,代码行数:103,代码来源:species_tests.py

示例2: TestSpecies

# 需要导入模块: from species import Species [as 别名]
# 或者: from species.Species import is_attackable [as 别名]
class TestSpecies(unittest.TestCase):

    def setUp(self):
        self.attacker = Species()
        self.attacker.traits = ["carnivore"]
        self.defender = Species()
        self.left_neighbor = Species()
        self.right_neighbor = Species()

        self.species_1 = Species(4, 4, 4)
        self.species_2 = Species(4, 4, 4)
        self.species_3 = Species(4, 4, 3)
        self.species_4 = Species(4, 3, 3)
        self.species_5 = Species(3, 3, 3)
        self.species_list = [self.species_2, self.species_4,
                             self.species_3, self.species_5, self.species_1]

    def test_can_eat(self):
        self.assertFalse(self.species_1.can_eat())
        self.assertTrue(self.species_4.can_eat())
        fat_tissue = Species(4, 3, 4, ["fat-tissue"], 3)
        self.assertTrue(fat_tissue.can_eat())
        fat_tissue.fat_storage = 4
        self.assertTrue(fat_tissue.can_eat())
        fat_tissue.food = 4
        self.assertFalse(fat_tissue.can_eat())

    def test_trait_names(self):
        self.assertEqual(self.defender.traits, [])
        self.assertEqual(self.attacker.traits, ["carnivore"])

    def test_attackable(self):
        self.assertTrue(self.defender.is_attackable(self.attacker))

    def test_no_carnivore(self):
        self.attacker.traits = []
        self.assertFalse(self.defender.is_attackable(self.attacker))

    def test_burrowing(self):
        self.defender.traits = ["burrowing"]
        self.defender.population, self.defender.food = (4, 4)
        self.assertFalse(self.defender.is_attackable(self.attacker))
        self.defender.food = 3
        self.assertTrue(self.defender.is_attackable(self.attacker))

    def test_climbing(self):
        self.defender.traits = ["climbing"]
        self.assertFalse(self.defender.is_attackable(self.attacker))
        self.attacker.traits.append("climbing")
        self.assertTrue(self.defender.is_attackable(self.attacker))

    def test_hard_shell(self):
        self.defender.traits = ["hard-shell"]
        self.defender.body = 3
        self.attacker.body = 6
        self.assertFalse(self.defender.is_attackable(self.attacker))
        self.attacker.body = 7
        self.assertTrue(self.defender.is_attackable(self.attacker))

    def test_herding(self):
        self.defender.traits = ["herding"]
        self.defender.population = 4
        self.attacker.population = 3
        self.assertFalse(self.defender.is_attackable(self.attacker))
        self.attacker.population = 5
        self.assertTrue(self.defender.is_attackable(self.attacker))

    def test_symbiosis(self):
        self.defender.traits = ["symbiosis"]
        self.defender.body = 3
        self.right_neighbor.body = 5
        self.assertFalse(self.defender.is_attackable(self.attacker,
                                                     right_neighbor=self.right_neighbor))
        self.right_neighbor.body = 2
        self.assertTrue(self.defender.is_attackable(self.attacker,
                                                    right_neighbor=self.right_neighbor))

    def test_warning_call(self):
        self.left_neighbor.traits = ["warning-call"]
        self.right_neighbor.traits = ["warning-call"]
        self.assertFalse(self.defender.is_attackable(self.attacker,
                                                     left_neighbor=self.left_neighbor))
        self.assertFalse(self.defender.is_attackable(self.attacker,
                                                     right_neighbor=self.right_neighbor))
        self.attacker.traits.append("ambush")
        self.assertTrue(self.defender.is_attackable(self.attacker,
                                                    left_neighbor=self.left_neighbor))
开发者ID:lydiaauch,项目名称:software-dev-2016,代码行数:89,代码来源:species_tests.py


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