Browse Source

Added tests for randIntRange

remotes/origin/encounter
János 2 years ago
parent
commit
ae5e7ef9c4
  1. 56
      test/c/test_encounter.c

56
test/c/test_encounter.c

@ -7,10 +7,8 @@
#include "helper.h" #include "helper.h"
#include "mock_helper.h" #include "mock_helper.h"
void setUp(void) void setUp(void)
{ {
} }
void teardown(void) void teardown(void)
@ -223,35 +221,35 @@ void test_FightPlayerChoosesAttack(void)
result = getEnemyHealth(&test); result = getEnemyHealth(&test);
// assert // assert
TEST_ASSERT_EQUAL(0, result); TEST_ASSERT_EQUAL(0, result);
}
}
void test_FightPlayerHeals_thenAttacks_Wins(void)
void test_FightPlayerHeals_thenAttacks_Wins(void)
{ {
//arrange
// arrange
int playerHealth = 2, playerDamage = 10, playerArmor = 4, playerAttack = 10; int playerHealth = 2, playerDamage = 10, playerArmor = 4, playerAttack = 10;
int enemyHealth = 11, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 5; int enemyHealth = 11, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 5;
int result; int result;
//act
// act
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth};
playerInput_ExpectAndReturn('h'); playerInput_ExpectAndReturn('h');
playerInput_ExpectAndReturn('a'); playerInput_ExpectAndReturn('a');
playerInput_ExpectAndReturn('a'); playerInput_ExpectAndReturn('a');
result = fight(playerHealth, playerDamage, playerArmor, playerAttack, &test); result = fight(playerHealth, playerDamage, playerArmor, playerAttack, &test);
//assert
// assert
TEST_ASSERT_EQUAL(1, result); TEST_ASSERT_EQUAL(1, result);
} }
void test_FightPlayerFlees(void) void test_FightPlayerFlees(void)
{ {
//arrange
// arrange
int playerHealth = 10, playerDamage = 10, playerArmor = 4, playerAttack = 10; int playerHealth = 10, playerDamage = 10, playerArmor = 4, playerAttack = 10;
int enemyHealth = 11, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 5; int enemyHealth = 11, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 5;
int result; int result;
//act
// act
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth};
playerInput_ExpectAndReturn('f'); playerInput_ExpectAndReturn('f');
result = fight(playerHealth, playerDamage, playerArmor, playerAttack, &test); result = fight(playerHealth, playerDamage, playerArmor, playerAttack, &test);
//assert
// assert
TEST_ASSERT_EQUAL(2, result); TEST_ASSERT_EQUAL(2, result);
} }
@ -265,30 +263,52 @@ void test_randomIntRange(void)
void test_enemyCanHeal(void) void test_enemyCanHeal(void)
{ {
//arrange
// arrange
int enemyHealth = 1, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 20; int enemyHealth = 1, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 20;
int healAmount= 10, expectedHealth = 11;
int healAmount = 10, expectedHealth = 11;
int result; int result;
//act
// act
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth};
enemyHeal(&test, healAmount); enemyHeal(&test, healAmount);
result = getEnemyHealth(&test); result = getEnemyHealth(&test);
//assert
// assert
TEST_ASSERT_EQUAL(expectedHealth, result); TEST_ASSERT_EQUAL(expectedHealth, result);
} }
void test_enemyNoOverheal(void) void test_enemyNoOverheal(void)
{ {
//arrange
// arrange
int enemyHealth = 1, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 5; int enemyHealth = 1, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 5;
int healAmount= 10, expectedHealth = 5;
int healAmount = 10, expectedHealth = 5;
int result; int result;
//act
// act
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth};
enemyHeal(&test, healAmount); enemyHeal(&test, healAmount);
result = getEnemyHealth(&test); result = getEnemyHealth(&test);
//assert
// assert
TEST_ASSERT_EQUAL(expectedHealth, result); TEST_ASSERT_EQUAL(expectedHealth, result);
} }
void test_roll_20()
{
int expected = 20;
int result;
randomInt_ExpectAndReturn(39);
result = randomIntRange(1, 20);
TEST_ASSERT_EQUAL(expected, result);
}
void test_roll_01()
{
int expected = 1;
int result;
randomInt_ExpectAndReturn(40);
result = randomIntRange(1, 20);
TEST_ASSERT_EQUAL(expected, result);
}
#endif // TEST #endif // TEST
Loading…
Cancel
Save