|
@ -5,160 +5,164 @@ |
|
|
#include "playerinput.h" |
|
|
#include "playerinput.h" |
|
|
#include "mock_playerinput.h" |
|
|
#include "mock_playerinput.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setUp(void){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setUp(void) |
|
|
|
|
|
{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void teardown(void){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void teardown(void) |
|
|
|
|
|
{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void test_isPlayerAlive_healthGreaterZero(void) |
|
|
void test_isPlayerAlive_healthGreaterZero(void) |
|
|
{ |
|
|
{ |
|
|
//arrange |
|
|
|
|
|
|
|
|
// arrange |
|
|
int health = 100; |
|
|
int health = 100; |
|
|
bool result; |
|
|
bool result; |
|
|
//act |
|
|
|
|
|
|
|
|
// act |
|
|
result = playerAlive(health); |
|
|
result = playerAlive(health); |
|
|
//assert |
|
|
|
|
|
|
|
|
// assert |
|
|
TEST_ASSERT_TRUE(result); |
|
|
TEST_ASSERT_TRUE(result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void test_isPlayerAlive_healthLowerZero(void) |
|
|
void test_isPlayerAlive_healthLowerZero(void) |
|
|
{ |
|
|
{ |
|
|
//arrange |
|
|
|
|
|
|
|
|
// arrange |
|
|
int health = -1; |
|
|
int health = -1; |
|
|
bool result; |
|
|
bool result; |
|
|
//act |
|
|
|
|
|
|
|
|
// act |
|
|
result = playerAlive(health); |
|
|
result = playerAlive(health); |
|
|
|
|
|
|
|
|
//assert |
|
|
|
|
|
|
|
|
// assert |
|
|
TEST_ASSERT_FALSE(result); |
|
|
TEST_ASSERT_FALSE(result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void test_playerIsDamaged(void) |
|
|
void test_playerIsDamaged(void) |
|
|
{ |
|
|
{ |
|
|
//arrange |
|
|
|
|
|
|
|
|
// arrange |
|
|
int health = 100; |
|
|
int health = 100; |
|
|
int damage = 10; |
|
|
int damage = 10; |
|
|
int armor = 0; |
|
|
int armor = 0; |
|
|
int expectedHealth = 90; |
|
|
int expectedHealth = 90; |
|
|
//act |
|
|
|
|
|
|
|
|
// act |
|
|
health = playerHealth(health, damage, armor); |
|
|
health = playerHealth(health, damage, armor); |
|
|
//assert |
|
|
|
|
|
|
|
|
// assert |
|
|
TEST_ASSERT_EQUAL(expectedHealth, health); |
|
|
TEST_ASSERT_EQUAL(expectedHealth, health); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void test_playerIsNotOverhealed(void){ |
|
|
|
|
|
//arrange |
|
|
|
|
|
|
|
|
void test_playerIsNotOverhealed(void) |
|
|
|
|
|
{ |
|
|
|
|
|
// arrange |
|
|
int health = 100; |
|
|
int health = 100; |
|
|
int armor = 0; |
|
|
int armor = 0; |
|
|
int heal = -10; |
|
|
int heal = -10; |
|
|
int expectedHealth = 100; |
|
|
int expectedHealth = 100; |
|
|
//act |
|
|
|
|
|
|
|
|
// act |
|
|
health = playerHealth(health, heal, armor); |
|
|
health = playerHealth(health, heal, armor); |
|
|
//assert |
|
|
|
|
|
|
|
|
// assert |
|
|
TEST_ASSERT_EQUAL(expectedHealth, health); |
|
|
TEST_ASSERT_EQUAL(expectedHealth, health); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void test_setEnemyHealth(void){ |
|
|
|
|
|
//arrange |
|
|
|
|
|
|
|
|
void test_setEnemyHealth(void) |
|
|
|
|
|
{ |
|
|
|
|
|
// arrange |
|
|
int health = 50, result; |
|
|
int health = 50, result; |
|
|
//act |
|
|
|
|
|
enemy test = {health*2}; |
|
|
|
|
|
|
|
|
// act |
|
|
|
|
|
enemy test = {health * 2}; |
|
|
setEnemyHealth(&test, health); |
|
|
setEnemyHealth(&test, health); |
|
|
result = test.health; |
|
|
result = test.health; |
|
|
//assert |
|
|
|
|
|
|
|
|
// assert |
|
|
TEST_ASSERT_EQUAL(health, result); |
|
|
TEST_ASSERT_EQUAL(health, result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void test_getEnemyHealth(void){ |
|
|
|
|
|
//arrange |
|
|
|
|
|
|
|
|
void test_getEnemyHealth(void) |
|
|
|
|
|
{ |
|
|
|
|
|
// arrange |
|
|
int health = 50, result; |
|
|
int health = 50, result; |
|
|
//act |
|
|
|
|
|
|
|
|
// act |
|
|
enemy test = {health}; |
|
|
enemy test = {health}; |
|
|
result = getEnemyHealth(&test); |
|
|
result = getEnemyHealth(&test); |
|
|
//assert |
|
|
|
|
|
|
|
|
// assert |
|
|
TEST_ASSERT_EQUAL(health, result); |
|
|
TEST_ASSERT_EQUAL(health, result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void test_setEnemyDamage(void){ |
|
|
|
|
|
//arrange |
|
|
|
|
|
|
|
|
void test_setEnemyDamage(void) |
|
|
|
|
|
{ |
|
|
|
|
|
// arrange |
|
|
int damage = 4, result; |
|
|
int damage = 4, result; |
|
|
enemy test = {50, damage*2}; |
|
|
|
|
|
//act |
|
|
|
|
|
|
|
|
enemy test = {50, damage * 2}; |
|
|
|
|
|
// act |
|
|
setEnemyDamage(&test, damage); |
|
|
setEnemyDamage(&test, damage); |
|
|
result = test.damage; |
|
|
result = test.damage; |
|
|
//assert |
|
|
|
|
|
|
|
|
// assert |
|
|
TEST_ASSERT_EQUAL(damage, result); |
|
|
TEST_ASSERT_EQUAL(damage, result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void test_getEnemyDamage(void){ |
|
|
|
|
|
//arrange |
|
|
|
|
|
|
|
|
void test_getEnemyDamage(void) |
|
|
|
|
|
{ |
|
|
|
|
|
// arrange |
|
|
int damage = 4, result; |
|
|
int damage = 4, result; |
|
|
//act |
|
|
|
|
|
|
|
|
// act |
|
|
enemy test = {50, damage}; |
|
|
enemy test = {50, damage}; |
|
|
result = getEnemyDamage(&test); |
|
|
result = getEnemyDamage(&test); |
|
|
//assert |
|
|
|
|
|
|
|
|
// assert |
|
|
TEST_ASSERT_EQUAL(damage, result); |
|
|
TEST_ASSERT_EQUAL(damage, result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void test_get_setEnemyArmor(void){ |
|
|
|
|
|
//arrange |
|
|
|
|
|
|
|
|
void test_get_setEnemyArmor(void) |
|
|
|
|
|
{ |
|
|
|
|
|
// arrange |
|
|
int armor = 4, result; |
|
|
int armor = 4, result; |
|
|
enemy test = {50, 4, armor*2}; |
|
|
|
|
|
//act |
|
|
|
|
|
|
|
|
enemy test = {50, 4, armor * 2}; |
|
|
|
|
|
// act |
|
|
setEnemyArmor(&test, armor); |
|
|
setEnemyArmor(&test, armor); |
|
|
result = getEnemyArmor(&test); |
|
|
result = getEnemyArmor(&test); |
|
|
//assert |
|
|
|
|
|
|
|
|
// assert |
|
|
TEST_ASSERT_EQUAL(armor, result); |
|
|
TEST_ASSERT_EQUAL(armor, result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void test_PlayerAttacksEnemy_DoesDamage(void) |
|
|
void test_PlayerAttacksEnemy_DoesDamage(void) |
|
|
{ |
|
|
{ |
|
|
//arrange |
|
|
|
|
|
|
|
|
// arrange |
|
|
int playerDamage = 10; |
|
|
int playerDamage = 10; |
|
|
int enemyHealth = 50; |
|
|
int enemyHealth = 50; |
|
|
int enemyArmor = 4; |
|
|
int enemyArmor = 4; |
|
|
//health - (damage - armor) |
|
|
|
|
|
|
|
|
// health - (damage - armor) |
|
|
int expectedEnemyHealth = 44; |
|
|
int expectedEnemyHealth = 44; |
|
|
//act |
|
|
|
|
|
|
|
|
// act |
|
|
enemy test = {enemyHealth, 4, enemyArmor}; |
|
|
enemy test = {enemyHealth, 4, enemyArmor}; |
|
|
enemyDamaged(&test, playerDamage); |
|
|
enemyDamaged(&test, playerDamage); |
|
|
//assert |
|
|
|
|
|
|
|
|
// assert |
|
|
TEST_ASSERT_EQUAL(expectedEnemyHealth, test.health); |
|
|
TEST_ASSERT_EQUAL(expectedEnemyHealth, test.health); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void test_PlayerAttacksEnemy_DoesMinDamage(void) |
|
|
void test_PlayerAttacksEnemy_DoesMinDamage(void) |
|
|
{ |
|
|
{ |
|
|
//arrange |
|
|
|
|
|
|
|
|
// arrange |
|
|
int playerDamage = 10; |
|
|
int playerDamage = 10; |
|
|
int enemyHealth = 50; |
|
|
int enemyHealth = 50; |
|
|
int enemyArmor = 10; |
|
|
int enemyArmor = 10; |
|
|
//health - (damage - armor) |
|
|
|
|
|
|
|
|
// health - (damage - armor) |
|
|
int expectedEnemyHealth = 49; |
|
|
int expectedEnemyHealth = 49; |
|
|
//act |
|
|
|
|
|
|
|
|
// act |
|
|
enemy test = {enemyHealth, 4, enemyArmor}; |
|
|
enemy test = {enemyHealth, 4, enemyArmor}; |
|
|
enemyDamaged(&test, playerDamage); |
|
|
enemyDamaged(&test, playerDamage); |
|
|
//assert |
|
|
|
|
|
|
|
|
// assert |
|
|
TEST_ASSERT_EQUAL(expectedEnemyHealth, test.health); |
|
|
TEST_ASSERT_EQUAL(expectedEnemyHealth, test.health); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//A better way to get the value of a struct, REFACTORING if it works |
|
|
|
|
|
|
|
|
// A better way to get the value of a struct, REFACTORING if it works |
|
|
void test_getterWithParams(void) |
|
|
void test_getterWithParams(void) |
|
|
{ |
|
|
{ |
|
|
//arrange |
|
|
|
|
|
|
|
|
// arrange |
|
|
int health = 50, armor = 4, damage = 4, attack = 5; |
|
|
int health = 50, armor = 4, damage = 4, attack = 5; |
|
|
int healthResult, armorResult, damageResult, attackResult; |
|
|
int healthResult, armorResult, damageResult, attackResult; |
|
|
enemy test = {health, damage, armor, attack}; |
|
|
enemy test = {health, damage, armor, attack}; |
|
|
//act |
|
|
|
|
|
|
|
|
// act |
|
|
healthResult = getEnemyHealth(&test); |
|
|
healthResult = getEnemyHealth(&test); |
|
|
armorResult = getEnemyArmor(&test); |
|
|
armorResult = getEnemyArmor(&test); |
|
|
damageResult = getEnemyDamage(&test); |
|
|
damageResult = getEnemyDamage(&test); |
|
|
attackResult = getEnemyAttack(&test); |
|
|
attackResult = getEnemyAttack(&test); |
|
|
//assert |
|
|
|
|
|
|
|
|
// assert |
|
|
TEST_ASSERT_EQUAL(health, healthResult); |
|
|
TEST_ASSERT_EQUAL(health, healthResult); |
|
|
TEST_ASSERT_EQUAL(armor, armorResult); |
|
|
TEST_ASSERT_EQUAL(armor, armorResult); |
|
|
TEST_ASSERT_EQUAL(damage, damageResult); |
|
|
TEST_ASSERT_EQUAL(damage, damageResult); |
|
@ -166,56 +170,71 @@ void test_getterWithParams(void) |
|
|
} |
|
|
} |
|
|
void test_switchingTurns(void) |
|
|
void test_switchingTurns(void) |
|
|
{ |
|
|
{ |
|
|
//arrange |
|
|
|
|
|
|
|
|
// arrange |
|
|
int currentTurn = 0, result; |
|
|
int currentTurn = 0, result; |
|
|
//act |
|
|
|
|
|
|
|
|
// act |
|
|
result = switchTurns(currentTurn); |
|
|
result = switchTurns(currentTurn); |
|
|
//assert |
|
|
|
|
|
TEST_ASSERT_EQUAL(1,result); |
|
|
|
|
|
|
|
|
// assert |
|
|
|
|
|
TEST_ASSERT_EQUAL(1, result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void test_FightPlayerWins(void) |
|
|
void test_FightPlayerWins(void) |
|
|
{ |
|
|
{ |
|
|
//arange |
|
|
|
|
|
|
|
|
// arange |
|
|
int playerHealth = 100, playerDamage = 10, playerArmor = 4, playerAttack = 5; |
|
|
int playerHealth = 100, playerDamage = 10, playerArmor = 4, playerAttack = 5; |
|
|
int enemyHealth = 1, enemyDamage = 4, enemyArmor = 4, enemyAttack = 5; |
|
|
int enemyHealth = 1, enemyDamage = 4, enemyArmor = 4, enemyAttack = 5; |
|
|
int result; |
|
|
int result; |
|
|
//aCt |
|
|
|
|
|
|
|
|
// aCt |
|
|
playerInput_ExpectAndReturn('a'); |
|
|
playerInput_ExpectAndReturn('a'); |
|
|
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyAttack}; |
|
|
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyAttack}; |
|
|
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_FightEnemyWins(void) |
|
|
void test_FightEnemyWins(void) |
|
|
{ |
|
|
{ |
|
|
//arange |
|
|
|
|
|
|
|
|
// arange |
|
|
int playerHealth = 1, playerDamage = 10, playerArmor = 4, playerAttack = 5; |
|
|
int playerHealth = 1, playerDamage = 10, playerArmor = 4, playerAttack = 5; |
|
|
int enemyHealth = 100, enemyDamage = 4, enemyArmor = 4, enemyAttack = 5; |
|
|
int enemyHealth = 100, enemyDamage = 4, enemyArmor = 4, enemyAttack = 5; |
|
|
int result; |
|
|
int result; |
|
|
//act |
|
|
|
|
|
|
|
|
// act |
|
|
playerInput_ExpectAndReturn('a'); |
|
|
playerInput_ExpectAndReturn('a'); |
|
|
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyAttack}; |
|
|
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyAttack}; |
|
|
result = fight(playerHealth, playerDamage, playerArmor, playerAttack, &test); |
|
|
result = fight(playerHealth, playerDamage, playerArmor, playerAttack, &test); |
|
|
//assert |
|
|
|
|
|
|
|
|
// assert |
|
|
TEST_ASSERT_EQUAL(0, result); |
|
|
TEST_ASSERT_EQUAL(0, result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void test_FightPlayerChoosesAttack(void){ |
|
|
|
|
|
//arrange |
|
|
|
|
|
|
|
|
void test_FightPlayerChoosesAttack(void) |
|
|
|
|
|
{ |
|
|
|
|
|
// arrange |
|
|
int playerHealth = 100, playerDamage = 10, playerArmor = 4, playerAttack = 5; |
|
|
int playerHealth = 100, playerDamage = 10, playerArmor = 4, playerAttack = 5; |
|
|
int enemyHealth = 100, enemyDamage = 4, enemyArmor = 4, enemyAttack = 5; |
|
|
|
|
|
|
|
|
int enemyHealth = 6, enemyDamage = 4, enemyArmor = 4, enemyAttack = 5; |
|
|
int result; |
|
|
int result; |
|
|
//act |
|
|
|
|
|
|
|
|
// act |
|
|
playerInput_ExpectAndReturn('a'); |
|
|
playerInput_ExpectAndReturn('a'); |
|
|
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyAttack}; |
|
|
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyAttack}; |
|
|
fight(playerHealth, playerDamage, playerArmor, playerAttack, &test); |
|
|
fight(playerHealth, playerDamage, playerArmor, playerAttack, &test); |
|
|
result = getEnemyHealth(&test); |
|
|
result = getEnemyHealth(&test); |
|
|
|
|
|
// assert |
|
|
|
|
|
TEST_ASSERT_EQUAL(0, result); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void test_FightPlayerHeals_thenAttacks_Wins(void) |
|
|
|
|
|
{ |
|
|
|
|
|
//arrange |
|
|
|
|
|
int playerHealth = 2, playerDamage = 10, playerArmor = 4, playerAttack = 10; |
|
|
|
|
|
int enemyHealth = 11, enemyDamage = 4, enemyArmor = 4, enemyAttack = 5; |
|
|
|
|
|
int result; |
|
|
|
|
|
//act |
|
|
|
|
|
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyAttack}; |
|
|
|
|
|
playerInput_ExpectAndReturn('h'); |
|
|
|
|
|
playerInput_ExpectAndReturn('a'); |
|
|
|
|
|
playerInput_ExpectAndReturn('a'); |
|
|
|
|
|
result = fight(playerHealth, playerDamage, playerArmor, playerAttack, &test); |
|
|
//assert |
|
|
//assert |
|
|
TEST_ASSERT_EQUAL(94, result); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL(1, result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // TEST |
|
|
#endif // TEST |