Browse Source

added addMoneyToPlayer with test

remotes/origin/navigation
KRUGSON 2 years ago
parent
commit
5b9fa5460a
  1. 15
      src/c/player.c
  2. 1
      src/c/player.h
  3. 19
      test/c/test_player.c

15
src/c/player.c

@ -5,10 +5,9 @@
#include "player.h"
// PLAYER INVENTORY
//add and remove
// add and remove
Player addItemToInventory(Item *availableItems, int itemIndex, Player actualPlayer)
{
int counter = actualPlayer.itemCounter;
@ -51,14 +50,21 @@ Player removeItemFromInventory(int itemIndex, Player actualPlayer)
return actualPlayer;
}
//currency
// currency
Player setTotal(Player actualPlayer, int value)
{
actualPlayer.wallet = value;
return actualPlayer;
}
//show
Player addMoneyToPlayer(Player actualPlayer, int money)
{
int newTotal = money + actualPlayer.wallet;
actualPlayer = setTotal(actualPlayer, newTotal);
return actualPlayer;
}
// show
void showInventory(Player actualPlayer)
{
int inventoryItemCounter = actualPlayer.itemCounter;
@ -80,4 +86,3 @@ void showInventory(Player actualPlayer)
printf("\n\n");
}

1
src/c/player.h

@ -17,6 +17,7 @@ Player removeItemFromInventory(int index, Player actualPlayer);
//currency
Player setTotal(Player actualPlayer, int value);
Player addMoneyToPlayer(Player actualPlayer, int money);
//show
void showInventory(Player actualPlayer);

19
test/c/test_player.c

@ -72,4 +72,23 @@ void test_setTotal(void)
TEST_ASSERT_NOT_EQUAL_UINT8(valueBefore, valueAfter);
}
void test_addMoneyToPlayer(void)
{
/* arrange */
// Hier die Werte eingeben/deklarieren
// balance = 70
int valueToAdd = 20;
int checkSum = actualPlayer.wallet + valueToAdd;
/* act */
// Die Funktion wird ausgeführt
actualPlayer = addMoneyToPlayer(actualPlayer, valueToAdd);
// OUTPUT
printf("%d$ has been added to your balance. TOTAL: %d$", valueToAdd, actualPlayer.wallet);
/* assert */
// Vergleichen mit Inhalt von game.Map File
TEST_ASSERT_EQUAL_INT(checkSum, actualPlayer.wallet);
}
#endif // TEST
Loading…
Cancel
Save