def test_unit_attack_exception(): soldier = Unit('Soldier', 10, 10, 20) warrior = Unit('Warrior', 10, 10, 20) with pytest.raises(UnitIsDeadException): soldier.attack(warrior) with pytest.raises(UnitIsDeadException): soldier.counterAttack(warrior) with pytest.raises(UnitIsDeadException): soldier.takeDamage(warrior.dmg)
def test_takeDamage(): unit1 = Unit('SoLdIeR', 100, 100, 10) unit1.takeDamage(40) assert unit1.hp == 60
def test_damage_greater_than_hp(): soldier = Unit('Soldier', 20, 20, 20) soldier.takeDamage(20) assert soldier.hp == 0