From ae5e7ef9c472402f79e586deff30e344a66687f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos?= Date: Mon, 23 Jan 2023 13:30:56 +0100 Subject: [PATCH] Added tests for randIntRange --- test/c/test_encounter.c | 56 ++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index 32d6d00..b9bc4de 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -7,10 +7,8 @@ #include "helper.h" #include "mock_helper.h" - void setUp(void) { - } void teardown(void) @@ -223,35 +221,35 @@ void test_FightPlayerChoosesAttack(void) result = getEnemyHealth(&test); // assert 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 enemyHealth = 11, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 5; int result; - //act + // act enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; playerInput_ExpectAndReturn('h'); playerInput_ExpectAndReturn('a'); playerInput_ExpectAndReturn('a'); result = fight(playerHealth, playerDamage, playerArmor, playerAttack, &test); - //assert + // assert TEST_ASSERT_EQUAL(1, result); } void test_FightPlayerFlees(void) { - //arrange + // arrange int playerHealth = 10, playerDamage = 10, playerArmor = 4, playerAttack = 10; int enemyHealth = 11, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 5; int result; - //act + // act enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; playerInput_ExpectAndReturn('f'); result = fight(playerHealth, playerDamage, playerArmor, playerAttack, &test); - //assert + // assert TEST_ASSERT_EQUAL(2, result); } @@ -265,30 +263,52 @@ void test_randomIntRange(void) void test_enemyCanHeal(void) { - //arrange + // arrange int enemyHealth = 1, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 20; - int healAmount= 10, expectedHealth = 11; + int healAmount = 10, expectedHealth = 11; int result; - //act + // act enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; enemyHeal(&test, healAmount); result = getEnemyHealth(&test); - //assert + // assert TEST_ASSERT_EQUAL(expectedHealth, result); } void test_enemyNoOverheal(void) { - //arrange + // arrange int enemyHealth = 1, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 5; - int healAmount= 10, expectedHealth = 5; + int healAmount = 10, expectedHealth = 5; int result; - //act + // act enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; enemyHeal(&test, healAmount); result = getEnemyHealth(&test); - //assert + // assert 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