diff --git a/src/c/encounter.c b/src/c/encounter.c index 955736e..fe37c67 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -65,6 +65,9 @@ int getEnemyArmor(enemy enemy){ int enemyDamaged(enemy enemy, int damage){ int armor = getEnemyArmor(enemy); int damagedealt = damage - armor; + if(damagedealt < 1){ + damagedealt = 1; + } enemy.health = enemy.health - damagedealt; return enemy.health; } \ No newline at end of file diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index 8bef335..1f501ae 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -100,5 +100,18 @@ void test_PlayerAttacksEnemy_DoesDamage(void) TEST_ASSERT_EQUAL(expectedEnemyHealth, test.health); } - +void test_PlayerAttacksEnemy_DoesMinDamage(void) +{ + //arrange + int playerDamage = 10; + int enemyHealth = 50; + int enemyArmor = 10; + //health - (damage - armor) + int expectedEnemyHealth = 49; + //act + enemy test = {enemyHealth, 4, enemyArmor}; + test.health = enemyDamaged(test, playerDamage); + //assert + TEST_ASSERT_EQUAL(expectedEnemyHealth, test.health); +} #endif // TEST