Browse Source

Added TurnSwitch and More Tests for all paths

remotes/origin/encounter
János 2 years ago
parent
commit
25432ede8b
  1. 3
      .gitignore
  2. 7
      src/c/encounter.c
  3. 3
      src/c/encounter.h
  4. 24
      test/c/test_encounter.c

3
.gitignore

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

7
src/c/encounter.c

@ -4,6 +4,7 @@
#include <stdbool.h>
#include "encounter.h"
/*Gegner mit AC, damagedealt = damage-AC, kann nicht kleiner 1 sein
evtl. lair bonus der dem gegner ein wenig mehr/weniger damage erlaubt
gegner erhalten eine zufällige menge Gold, die beim tod an den spieler gegeben werden
@ -58,3 +59,9 @@ void *setEnemyArmor(int *num, int armor){
int getEnemyInt(int *structParam){
return *structParam;
}
int switchTurns(int currentTurn){
currentTurn = currentTurn % 2 + 1;
return currentTurn;
}

3
src/c/encounter.h

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

24
test/c/test_encounter.c

@ -4,6 +4,7 @@
#include "encounter.h"
void setUp(void){
}
@ -21,6 +22,15 @@ void test_isPlayerAlive_healthGreaterZero(void)
TEST_ASSERT_TRUE(playerAlive(health));
}
void test_isPlayerAlive_healthLowerZero(void)
{
//arrange
int health = -1;
//act
//assert
TEST_ASSERT_TRUE(playerAlive(health));
}
void test_playerIsDamaged(void)
{
//arrange
@ -117,7 +127,8 @@ void test_PlayerAttacksEnemy_DoesMinDamage(void)
}
//A better way to get the value of a struct, REFACTORING if it works
void test_getterWithParams(void){
void test_getterWithParams(void)
{
int health = 50, armor = 4, damage = 4, attack = 5;
enemy test = {health, damage, armor, attack};
TEST_ASSERT_EQUAL(health, getEnemyInt(&test.health));
@ -125,4 +136,15 @@ 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