Browse Source

added removeMoneyFromPlayer with test

remotes/origin/navigation
KRUGSON 2 years ago
parent
commit
35f45ee77a
  1. 7
      src/c/player.c
  2. 1
      src/c/player.h
  3. 23
      test/c/test_player.c

7
src/c/player.c

@ -64,6 +64,13 @@ Player addMoneyToPlayer(Player actualPlayer, int money)
return actualPlayer; return actualPlayer;
} }
Player removeMoneyFromPlayer(Player actualPlayer, int money)
{
int newTotal = actualPlayer.wallet - money;
actualPlayer = setTotal(actualPlayer, newTotal);
return actualPlayer;
}
// show // show
void showInventory(Player actualPlayer) void showInventory(Player actualPlayer)
{ {

1
src/c/player.h

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

23
test/c/test_player.c

@ -79,6 +79,7 @@ void test_addMoneyToPlayer(void)
// balance = 70 // balance = 70
int valueToAdd = 20; int valueToAdd = 20;
int checkSum = actualPlayer.wallet + valueToAdd; int checkSum = actualPlayer.wallet + valueToAdd;
/* act */ /* act */
// Die Funktion wird ausgeführt // Die Funktion wird ausgeführt
actualPlayer = addMoneyToPlayer(actualPlayer, valueToAdd); actualPlayer = addMoneyToPlayer(actualPlayer, valueToAdd);
@ -91,4 +92,26 @@ void test_addMoneyToPlayer(void)
TEST_ASSERT_EQUAL_INT(checkSum, actualPlayer.wallet); TEST_ASSERT_EQUAL_INT(checkSum, actualPlayer.wallet);
} }
void test_removeMoneyFromPlayer(void)
{
/* arrange */
// Hier die Werte eingeben/deklarieren
int valueToRemove = 20;
int checkSum = actualPlayer.wallet - valueToRemove;
/* act */
// Die Funktion wird ausgeführt
actualPlayer = removeMoneyFromPlayer(actualPlayer, valueToRemove);
// OUTPUT
printf("%d$ has been removed from your balance. TOTAL: %d$", valueToRemove, actualPlayer.wallet);
/* assert */
// Vergleichen mit Inhalt von game.Map File
TEST_ASSERT_EQUAL_INT(checkSum, actualPlayer.wallet);
}
#endif // TEST #endif // TEST
Loading…
Cancel
Save