Browse Source

added sellItem with test

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

7
src/c/player.c

@ -89,6 +89,13 @@ Player buyItem(Item *availableItems, int itemIndex, Player actualPlayer)
}
}
Player sellItem(int itemIndex, Player actualPlayer)
{
actualPlayer = addMoneyToPlayer(actualPlayer, actualPlayer.itemInventory[itemIndex].price / 2);
actualPlayer = removeItemFromInventory(itemIndex, actualPlayer);
printf("Item has been sold! Your balance is now: %d$\n", actualPlayer.wallet);
return actualPlayer;
}
// show
void showInventory(Player actualPlayer)

1
src/c/player.h

@ -22,6 +22,7 @@ Player removeMoneyFromPlayer(Player actualPlayer, int money);
//add and remove items with currency
Player buyItem(Item *availableItems, int itemIndex, Player actualPlayer);
Player sellItem(int itemIndex, Player actualPlayer);
//show
void showInventory(Player actualPlayer);

22
test/c/test_player.c

@ -129,5 +129,27 @@ void test_buyItem(void)
}
void test_sellItem(void)
{
/* arrange */
// Hier die Werte eingeben/deklarieren
int buyItemID = 1; // prepare sell
actualPlayer = addItemToInventory(availableItems, buyItemID, actualPlayer); // prepare sell
int itemToRemove = 0; // index to remove (we already bought it in function above)
/* act */
// Die Funktion wird ausgeführt
Item itemBeforeRemove = actualPlayer.itemInventory[0];
actualPlayer = sellItem(itemToRemove, actualPlayer); // then remove
Item itemAfterRemove = actualPlayer.itemInventory[0];
// OUTPUT
//printf("sellItem | before: %d -> after: %d", itemBeforeRemove.id, itemAfterRemove.id);
/* assert */
// Vergleichen mit Inhalt von game.Map File
TEST_ASSERT_NOT_EQUAL_UINT8(itemBeforeRemove.id, itemAfterRemove.id);
}
#endif // TEST
Loading…
Cancel
Save