Browse Source

Added Test for all paths and switchPlayer Function

remotes/origin/encounter
János 2 years ago
parent
commit
26578ac18c
  1. 3
      .gitignore
  2. 5
      src/c/encounter.c
  3. 2
      src/c/encounter.h
  4. 20
      test/c/test_encounter.c

3
.gitignore

@ -3,4 +3,5 @@ build/gcov
builld/logs
build/temp
build/test
.vscode
.vscode
encounter_test.sh

5
src/c/encounter.c

@ -58,3 +58,8 @@ void *setEnemyArmor(int *num, int armor){
int getEnemyInt(int *structParam){
return *structParam;
}
int switchTurns(int currentTurn){
currentTurn = currentTurn % 2 + 1;
return currentTurn;
}

2
src/c/encounter.h

@ -14,7 +14,7 @@ typedef struct {
bool playerAlive(int health);
int playerHealth(int health, int damage);
int enemyDamaged(enemy enemy, int damage);
int switchTurns(int currentTurn);
//Getter/Setter Funktionen

20
test/c/test_encounter.c

@ -21,6 +21,16 @@ void test_isPlayerAlive_healthGreaterZero(void)
TEST_ASSERT_TRUE(playerAlive(health));
}
void test_isPlayerAlive_healthLowerZero(void)
{
//arrange
int health = -1;
//act
//assert
TEST_ASSERT_FALSE(playerAlive(health));
}
void test_playerIsDamaged(void)
{
//arrange
@ -125,4 +135,14 @@ void test_getterWithParams(void){
TEST_ASSERT_EQUAL(damage, getEnemyInt(&test.damage));
TEST_ASSERT_EQUAL(attack, getEnemyInt(&test.attack));
}
void test_switchingTurns(void)
{
//arrange
int currentTurn = 0, result;
//act
result = switchTurns(currentTurn);
//assert
TEST_ASSERT_EQUAL(1,result);
}
#endif // TEST
Loading…
Cancel
Save