From 11d7f06b92861a1c8d69ad6d7509a6abfb6bd6d2 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:45:32 +0100 Subject: [PATCH] added setTotal with test --- src/c/player.c | 7 +++++++ src/c/player.h | 5 +++++ test/c/test_player.c | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/c/player.c b/src/c/player.c index 355801f..83596a9 100644 --- a/src/c/player.c +++ b/src/c/player.c @@ -51,6 +51,13 @@ Player removeItemFromInventory(int itemIndex, Player actualPlayer) return actualPlayer; } +//currency +Player setTotal(Player actualPlayer, int value) +{ + actualPlayer.wallet = value; + return actualPlayer; +} + //show void showInventory(Player actualPlayer) { diff --git a/src/c/player.h b/src/c/player.h index 2bfeb06..e5191fa 100644 --- a/src/c/player.h +++ b/src/c/player.h @@ -11,9 +11,14 @@ typedef struct int wallet; } Player; +//add and remove items Player addItemToInventory(Item *availableItem, int itemIndex, Player actualPlayer); Player removeItemFromInventory(int index, Player actualPlayer); +//currency +Player setTotal(Player actualPlayer, int value); + +//show void showInventory(Player actualPlayer); #endif \ No newline at end of file diff --git a/test/c/test_player.c b/test/c/test_player.c index 012e4be..4763d43 100644 --- a/test/c/test_player.c +++ b/test/c/test_player.c @@ -44,10 +44,32 @@ void test_removeItemFromInventory(void) Item itemAfterRemove = actualPlayer.itemInventory[0]; // OUTPUT + printf("removeItem | ID_before: %d -> ID_after: %d", itemBeforeRemove.id, itemAfterRemove.id); /* assert */ // Vergleichen mit Inhalt von game.Map File TEST_ASSERT_NOT_EQUAL_UINT8(itemBeforeRemove.id, itemAfterRemove.id); } +void test_setTotal(void) +{ + /* arrange */ + // Hier die Werte eingeben/deklarieren + int setMoney = 100; + + /* act */ + // Die Funktion wird ausgeführt + int valueBefore = actualPlayer.wallet; + actualPlayer = setTotal(actualPlayer, setMoney); + int valueAfter = actualPlayer.wallet; + + // OUTPUT + printf("setTotal | before: %d -> after: %d", valueBefore, valueAfter); + + /* assert */ + // Vergleichen mit Inhalt + TEST_ASSERT_EQUAL_INT(setMoney, actualPlayer.wallet); + TEST_ASSERT_NOT_EQUAL_UINT8(valueBefore, valueAfter); +} + #endif // TEST