From e6dd447cc57586bb07ecae173f94ce327576bef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos?= Date: Mon, 9 Jan 2023 22:02:25 +0100 Subject: [PATCH] added encounter.c --- src/c/encounter.c | 24 +++++++++++++++++++++ src/c/encounter.h | 9 ++++++++ test/c/test_encounter.c | 46 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/c/encounter.c create mode 100644 src/c/encounter.h create mode 100644 test/c/test_encounter.c diff --git a/src/c/encounter.c b/src/c/encounter.c new file mode 100644 index 0000000..87eca2d --- /dev/null +++ b/src/c/encounter.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +#include + +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; +} diff --git a/src/c/encounter.h b/src/c/encounter.h new file mode 100644 index 0000000..16cea26 --- /dev/null +++ b/src/c/encounter.h @@ -0,0 +1,9 @@ +#ifndef ENCOUNTER_H +#define ENCOUNTER_H + +#include + +bool playerAlive(int health); +int playerHealth(int health, int damage); + +#endif \ No newline at end of file diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c new file mode 100644 index 0000000..2af8a8b --- /dev/null +++ b/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