Browse Source

Function to get random nums in range

remotes/origin/encounter
János 2 years ago
parent
commit
e26d326853
  1. 7
      src/c/encounter.c
  2. 2
      src/c/encounter.h
  3. 2
      src/c/helper.c
  4. 3
      src/c/helper.h
  5. 13
      test/c/test_encounter.c
  6. 23
      test/c/test_helper.c

7
src/c/encounter.c

@ -5,6 +5,7 @@
#include "encounter.h"
#include "playerinput.h"
#include "helper.h"
/*Gegner mit AC, damagedealt = damage-AC, kann nicht kleiner 1 sein
evtl. lair bonus der dem gegner ein wenig mehr/weniger damage erlaubt
@ -93,6 +94,12 @@ int fight(int playerH, int playerDamage, int playerArmor, int playerAttack, enem
}
}
int randomIntRange(int min, int max)
{
int value = randomInt();
return (value % (max - min + 1)) + min;
}
// Getter/Setter Funktionen
void setEnemyHealth(enemy* enemy, int newhealth)

2
src/c/encounter.h

@ -18,6 +18,8 @@ int switchTurns(int currentTurn);
int fight(int playerH, int playerDamage, int playerArmor, int playerAttack, enemy* enemy);
int randomIntRange(int min, int max);
//Getter/Setter Funktionen
//setEnemyHealth(&enemy, health);

2
src/c/helper.c

@ -3,4 +3,4 @@
int randomInt()
{
return rand();
}
}

3
src/c/helper.h

@ -2,6 +2,7 @@
#define HELPER_H
//erlaubt es z.b. rand() zu mocken
int randomInt;
int randomInt();
#endif

13
test/c/test_encounter.c

@ -4,9 +4,13 @@
#include "encounter.h"
#include "playerinput.h"
#include "mock_playerinput.h"
#include "helper.h"
#include "mock_helper.h"
void setUp(void)
{
}
void teardown(void)
@ -251,4 +255,13 @@ void test_FightPlayerFlees(void)
TEST_ASSERT_EQUAL(2, result);
}
void test_randomIntRange(void)
{
int expected = 4;
randomInt_ExpectAndReturn(15);
int result = randomIntRange(1, 6);
TEST_ASSERT_EQUAL_INT(expected, result);
}
#endif // TEST

23
test/c/test_helper.c

@ -0,0 +1,23 @@
#ifdef TEST
#include "unity.h"
#include "helper.h"
#include "mock_helper.h"
void setUp(void)
{
}
void teardown(void)
{
}
//Just to test the mock
void test_randomInt(void)
{
int expected = 42;
randomInt_ExpectAndReturn(expected);
TEST_ASSERT_EQUAL_INT(expected, randomInt());
}
#endif//Test
Loading…
Cancel
Save