Browse Source

added encounter.c

remotes/origin/encounter
János 2 years ago
parent
commit
e6dd447cc5
  1. 24
      src/c/encounter.c
  2. 9
      src/c/encounter.h
  3. 46
      test/c/test_encounter.c

24
src/c/encounter.c

@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <encounter.h>
bool playerAlive(int health){
if(health > 0){
return true;
}
else{
return false;
}
}
int playerHealth(int health, int damage){
const int maxhealth = 100;
health = health - damage;
if(health > maxhealth){
health = maxhealth;
}
return health;
}

9
src/c/encounter.h

@ -0,0 +1,9 @@
#ifndef ENCOUNTER_H
#define ENCOUNTER_H
#include <stdbool.h>
bool playerAlive(int health);
int playerHealth(int health, int damage);
#endif

46
test/c/test_encounter.c

@ -0,0 +1,46 @@
#ifdef TEST
#include "unity.h"
#include "encounter.h"
void setUp(void){
}
void teardown(void){
}
void test_isPlayerAlive_healthGreaterZero(void)
{
//arrange
int health = 100;
//act
//assert
TEST_ASSERT_TRUE(playerAlive(health));
}
void test_playerIsDamaged(void)
{
//arrange
int health = 100;
int damage = 10;
int expectedHealth = 90;
//act
health = playerHealth(health, damage);
//assert
TEST_ASSERT_EQUAL(expectedHealth, health);
}
void test_playerIsNotOverhealed(void){
//arrange
int health = 100;
int heal = -10;
int expectedHealth = 100;
//act
health = playerHealth(health, heal);
//assert
TEST_ASSERT_EQUAL(expectedHealth, health);
}
#endif // TEST
Loading…
Cancel
Save