From 5b9fa5460a13af867b6e211a04cdb5a90b0e7435 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:46:13 +0100 Subject: [PATCH] added addMoneyToPlayer with test --- src/c/player.c | 15 ++++++++++----- src/c/player.h | 1 + test/c/test_player.c | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/c/player.c b/src/c/player.c index 83596a9..eea802d 100644 --- a/src/c/player.c +++ b/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"); } - diff --git a/src/c/player.h b/src/c/player.h index e5191fa..5569f6c 100644 --- a/src/c/player.h +++ b/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); diff --git a/test/c/test_player.c b/test/c/test_player.c index 4763d43..e3c708d 100644 --- a/test/c/test_player.c +++ b/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