Пример #1
0
    def test_when_human_has_more_armor_than_damage_taken_then_dont_take_damage(
            self):
        human = Human(health=100, mana=100)
        armor = Armor(name="Dragon Armor", armor_points=30)
        armor.equip_to(human)

        human.take_damage(20)

        self.assertEqual(getattr(human, 'health'), 100)
        self.assertEqual(getattr(human, 'armor'), armor)
Пример #2
0
    def test_human_take_damage_method_changes_health_to_zero_if_damage_greater_than_health(
            self):
        test_health = 50
        test_mana = 55

        test_obj = Human(test_health, test_mana)

        test_obj.take_damage(150)

        self.assertEqual(getattr(test_obj, 'health'), 0)
Пример #3
0
    def test_human_take_damage_method_works_as_expected_if_health_greater_than_damage(
            self):
        test_health = 50
        test_mana = 55

        test_obj = Human(test_health, test_mana)

        test_obj.take_damage(25)

        self.assertEqual(getattr(test_obj, 'health'), 25)
Пример #4
0
    def test_human_take_damage_method_raises_typeerror_if_damage_is_not_int_or_float(
            self):
        test_health = 100
        test_mana = 55
        test_obj = Human(test_health, test_mana)
        exc = None

        try:
            test_obj.take_damage('p')
        except TypeError as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'Damage must be of "int" / "float" type.')