Browse Source

refactoring: changed the return type of spells to new Struct SpellEffect and updated tests to resemble this

remotes/origin/nextcycle
Kai Kehres 2 years ago
parent
commit
28b4f0e1ac
  1. 24
      src/c/spell.c
  2. 13
      src/c/spell.h
  3. 15
      test/c/test_spell.c

24
src/c/spell.c

@ -3,14 +3,24 @@
#include <string.h> #include <string.h>
#include "character.h" #include "character.h"
#include "spell.h"
int spellFireball(Character *character) {
int damage = 10 + (getCharacterIntelligence(character) / 2);
return damage;
SpellEffect spellFireball(Character *character) {
SpellEffect fireball;
fireball.damage = 10 + (getCharacterIntelligence(character) / 2);
fireball.healing = 0;
fireball.manaCost = 10;
fireball.effect = SPELL_EFFECT_NONE;
fireball.effectDuration = 0;
return fireball;
} }
int spellHeal(Character *character) {
int heal = 10 + (getCharacterIntelligence(character) / 3);
SpellEffect spellHeal(Character *character) {
SpellEffect heal;
heal.damage = 0;
heal.healing = 10 + (getCharacterIntelligence(character) / 3);
heal.manaCost = 10;
heal.effect = SPELL_EFFECT_NONE;
heal.effectDuration = 0;
return heal; return heal;
}
}

13
src/c/spell.h

@ -3,7 +3,16 @@
#include "character.h" #include "character.h"
int spellFireball(Character *character);
int spellHeal(Character *character);
typedef struct {
int damage, healing, manaCost, effect, effectDuration;
} SpellEffect;
enum {
SPELL_EFFECT_NONE = 0, SPELL_EFFECT_BURN = 1, SPELL_EFFECT_FREEZE = 2, SPELL_EFFECT_STUN =3 , SPELL_EFFECT_REGENERATION = 4
};
SpellEffect spellFireball(Character *character);
SpellEffect spellHeal(Character *character);
#endif #endif

15
test/c/test_spell.c

@ -32,13 +32,20 @@ void tearDown(void)
void test_spellFireball(void) void test_spellFireball(void)
{ {
TEST_ASSERT_EQUAL_INT(10,spellFireball(&testCharacter));
TEST_ASSERT_EQUAL_INT(13,spellFireball(&testCharacter2));
int result = spellFireball(&testCharacter).damage;
TEST_ASSERT_EQUAL_INT(10,result);
result = spellFireball(&testCharacter2).damage;
TEST_ASSERT_EQUAL_INT(13,result);
} }
void test_spellHeal(void) void test_spellHeal(void)
{ {
TEST_ASSERT_EQUAL_INT(10,spellHeal(&testCharacter));
TEST_ASSERT_EQUAL_INT(12,spellHeal(&testCharacter2));
int result = spellHeal(&testCharacter).healing;
TEST_ASSERT_EQUAL_INT(10,result);
result = spellHeal(&testCharacter2).healing;
TEST_ASSERT_EQUAL_INT(12,result);
} }
#endif // TEST #endif // TEST
Loading…
Cancel
Save