Browse Source

refactoring: changed playerDamaged Parameters and Unittest setup to resemble the changes

remotes/origin/thirdcycle
Kai Kehres 2 years ago
parent
commit
7780e81c61
  1. 8
      src/c/encounter.c
  2. 2
      src/c/encounter.h
  3. 10
      test/c/test_encounter.c

8
src/c/encounter.c

@ -39,14 +39,14 @@ int playerHeal(Character* character, int amount)
return getCharacterHealthPoints(character); return getCharacterHealthPoints(character);
} }
int playerDamaged(int health, int damage, int armor, Character* character)
int playerDamaged(enemy* enemy, Character* character)
{ {
int damagedealt = damage - armor;
int damagedealt = getEnemyDamage(enemy) - getCharacterArmor(character);
if (damagedealt < 1) if (damagedealt < 1)
{ {
damagedealt = 1; damagedealt = 1;
} }
return health - damagedealt;
return getCharacterHealthPoints(character) - damagedealt;
} }
void enemyHeal(enemy *enemy, int healAmount) void enemyHeal(enemy *enemy, int healAmount)
@ -111,7 +111,7 @@ int fight(Character *character, enemy* enemy)
} }
else else
{ {
playerH = playerDamaged(getCharacterHealthPoints(character), getEnemyDamage(enemy), getCharacterArmor(character), character);
playerH = playerDamaged(enemy, character);
setCharacterHealthPoints(character, playerH); setCharacterHealthPoints(character, playerH);
} }
} }

2
src/c/encounter.h

@ -16,7 +16,7 @@ typedef struct enemy{
bool playerAlive(Character *character); bool playerAlive(Character *character);
int playerHeal(Character* character,int amount); int playerHeal(Character* character,int amount);
int playerDamaged(int health, int damage, int armor, Character* character);
int playerDamaged(enemy* enemy, Character* character);
int rollInitiative (Character *character); int rollInitiative (Character *character);
void enemyHeal(enemy *enemy, int healAmount); void enemyHeal(enemy *enemy, int healAmount);
void enemyDamaged(enemy* enemy, int damage); void enemyDamaged(enemy* enemy, int damage);

10
test/c/test_encounter.c

@ -10,11 +10,14 @@
#include "utils.h" #include "utils.h"
Character testcharacter; Character testcharacter;
enemy testenemy;
void setUp(void) void setUp(void)
{ {
testcharacter.dexterity = 5; testcharacter.dexterity = 5;
testcharacter.healthPoints = 100; testcharacter.healthPoints = 100;
testcharacter.maxHealthPoints = 100; testcharacter.maxHealthPoints = 100;
testenemy.damage = 10;
} }
void teardown(void) void teardown(void)
@ -47,15 +50,10 @@ void test_isPlayerAlive_healthLowerZero(void)
void test_playerIsDamaged(void) void test_playerIsDamaged(void)
{ {
// arrange // arrange
int health = 100;
int damage = 10;
int armor = 0;
int expectedHealth = 90; int expectedHealth = 90;
// act // act
Character testChar = {10,10,10,health,100,1,0,100,damage,armor,100};
health = playerDamaged(health, damage, armor, &testChar);
// assert // assert
TEST_ASSERT_EQUAL(expectedHealth, health);
TEST_ASSERT_EQUAL(expectedHealth, playerDamaged(&testenemy, &testcharacter));
} }
void test_playerIsNotOverhealed(void) void test_playerIsNotOverhealed(void)

Loading…
Cancel
Save