Ejemplo n.º 1
0
class SpellTest(unittest.TestCase):
    def setUp(self):
        self.my_spell = Spell(name="Fireball",
                              damage=30,
                              mana_cost=50,
                              cast_range=2)

    def test_create_spell(self):
        self.assertTrue(isinstance(self.my_spell, Spell))

    def test_get_name(self):
        self.assertEqual(self.my_spell.get_name(), "Fireball")

    def test_get_damage(self):
        self.assertEqual(self.my_spell.get_damage(), 30)

    def test_get_mana_cost(self):
        self.assertEqual(self.my_spell.get_mana_cost(), 50)

    def test_get_cast_range(self):
        self.assertEqual(self.my_spell.get_cast_range(), 2)

    def test_dunder_str(self):
        self.assertEqual(str(self.my_spell), "Fireball")

    def test_dunder_repr(self):
        self.assertEqual(repr(self.my_spell), "Fireball")
Ejemplo n.º 2
0
class WeaponTest(unittest.TestCase):
    def setUp(self):
        self.spell = Spell("Abracadabra", 100, 11, 15)

    def test_damage(self):
        self.assertEqual(self.spell.get_damage(), 100)

    def test_name(self):
        self.assertEqual(self.spell.get_name(), 'Abracadabra')

    def test_mana_cost(self):
        self.assertEqual(self.spell.get_mana_cost(), 11)

    def test_cast_range(self):
        self.assertEqual(self.spell.get_cast_range(), 15)
class SpellTest(unittest.TestCase):

    def setUp(self):
        self.spell = Spell("Froze", 20, 10, 3)

    def test_is_instance(self):
        self.assertTrue(isinstance(self.spell, Spell))

    def test_valid_members(self):
        self.assertEqual(self.spell.name, "Froze")
        self.assertEqual(self.spell.damage, 20)
        self.assertEqual(self.spell.mana_cost, 10)
        self.assertEqual(self.spell.cast_range, 3)

    def test_str(self):
        name = self.spell.name
        damage = self.spell.damage
        mana_cost = self.spell.mana_cost
        cast_range = self.spell.cast_range

        expected = "{} with damage: {}, mana_cost: {}, cast_range: {}"
        expected = expected.format(name, damage, mana_cost, cast_range)
        self.assertEqual(str(self.spell), expected)

    def test_get_functions(self):
        self.assertEqual(self.spell.get_name(), "Froze")
        self.assertEqual(self.spell.get_damage(), 20)
        self.assertEqual(self.spell.get_mana_cost(), 10)
        self.assertEqual(self.spell.get_cast_range(), 3)

    def test_prepare_json(self):
        data = {
            "name": "Froze",
            "damage": 20,
            "mana_cost": 10,
            "cast_range": 3
        }
        self.assertEqual(self.spell.prepare_json(), data)
Ejemplo n.º 4
0
class HeroTest(unittest.TestCase):

    def setUp(self):
        self.hero = Hero(name="Bron",
                         title="Dragonslayer",
                         health=100, mana=100,
                         mana_regeneration_rate=2)
        self.weapon = Weapon(name="The Axe of Destiny", damage=20)
        self.spell = Spell(name="Fireball",
                           damage=30,
                           mana_cost=50,
                           cast_range=2)

    def test_exists_class(self):
        self.assertTrue(isinstance(self.hero, Hero))

    def test_hero_known_as(self):
        self.assertTrue(self.hero.known_as(), "Bron the DragonSlayer")

    def test_hero_is_alive(self):
        self.assertTrue(self.hero.is_alive(), True)

    def test_is_hero_not_alive(self):
        self.hero.reduce_health(100)
        self.assertFalse(self.hero.is_alive())

    def test_hero_can_cast(self):
        self.assertTrue(self.hero.can_cast(), True)

    def test_hero_can_cast_false(self):
        self.hero.reduce_mana(100)
        self.assertFalse(self.hero.can_cast())

    def test_mana_regeneration_rate(self):
        self.assertEqual(self.hero.mana_regeneration_rate(), 2)

    def test_hero_take_damage(self):
        damage_points = 20
        self.hero.take_damage(damage_points)
        self.assertEqual(self.hero.get_health(), 80)

    def test_hero_take_healing(self):
        healing_points = 20
        damage_points = 90
        self.hero.take_damage(damage_points)
        self.hero.take_healing(healing_points)
        self.assertTrue(self.hero.get_health(), 30)

    def test_hero_take_mana(self):
        damage_points = 50
        mana_points = 40
        new_mana_points = 20
        self.hero.take_damage(damage_points)
        self.hero.reduce_mana(mana_points)
        self.assertTrue(self.hero.take_mana(new_mana_points), 80)

    def test_hero_weapon(self):
        weapon_equipment = []
        weapon_equipment.append(self.weapon)
        self.assertEqual(weapon_equipment[0], self.weapon)

    def test_hero_can_equip_with_weapon(self):
        self.hero.equip(self.weapon)
        self.assertEqual(str(self.hero.weapon_equipment[0]),
                         self.weapon.get_name())

    def test_hero_spell(self):
        learned_spell = []
        learned_spell.append(self.spell)
        self.assertEqual(learned_spell[0], self.spell)

    def test_hero_can_learn_new_spell(self):
        self.hero.learn(self.spell)
        self.assertEqual(str(self.hero.learned_spell[0]),
                         self.spell.get_name())

    def test_hero_attack_with_spell(self):
        self.hero.learn(self.spell)
        self.assertEqual(self.hero.attack(by="spell"),
                         self.spell.get_damage())

    def test_hero_attack_with_weapon(self):
        self.hero.equip(self.weapon)
        self.assertEqual(self.hero.attack(by="weapon"),
                         self.weapon.get_damage())