Browse Source

prod/test: created function rollInitiative and Unittest

remotes/origin/thirdcycle
Kai Kehres 2 years ago
parent
commit
eb7b7c07f6
  1. 4
      src/c/encounter.c
  2. 1
      src/c/encounter.h
  3. 7
      test/c/test_encounter.c

4
src/c/encounter.c

@ -130,7 +130,9 @@ int fight(Character *character, enemy* enemy)
}
}
int rollInitiative (Character *character) {
return randomIntRange(1,20) + character->dexterity;
}
bool enemyChoosesHeal(enemy* enemy)
{

1
src/c/encounter.h

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

7
test/c/test_encounter.c

@ -9,9 +9,10 @@
#include "mock_helper.h"
#include "utils.h"
Character testcharacter;
void setUp(void)
{
testcharacter.dexterity = 5;
}
void teardown(void)
@ -395,5 +396,7 @@ void test_enemyHealsNoPotion(void)
TEST_ASSERT_FALSE(result);
}
int test_rollInitiative (void) {
TEST_ASSERT(testcharacter.dexterity + 1 <= rollInitiative(&testcharacter) && testcharacter.dexterity + 20 >= rollInitiative(&testcharacter));
}
#endif // TEST
Loading…
Cancel
Save