From 218a01068dd47a2a19dd9f00a3518ba1042d5dea Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:55:09 +0100 Subject: [PATCH] added setItemPrice with test --- src/c/items.c | 6 ++++++ src/c/items.h | 2 ++ test/c/test_items.c | 22 ++++++++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/c/items.c b/src/c/items.c index 191051a..7f09bd5 100644 --- a/src/c/items.c +++ b/src/c/items.c @@ -55,3 +55,9 @@ Item *getItems(char *itemsMapFile) } return getItems; } + + +void setItemPrice(Item* item, int price) +{ + item->price = price; +} \ No newline at end of file diff --git a/src/c/items.h b/src/c/items.h index ed50446..143006f 100644 --- a/src/c/items.h +++ b/src/c/items.h @@ -17,4 +17,6 @@ typedef struct Item *getItems(char *itemsMapFile); +void setItemPrice(Item* item, int price); + #endif \ No newline at end of file diff --git a/test/c/test_items.c b/test/c/test_items.c index 9fc3ce3..f9bf002 100644 --- a/test/c/test_items.c +++ b/test/c/test_items.c @@ -16,7 +16,7 @@ void test_items(void) { /* arrange */ // Hier die Werte eingeben/deklarieren - Item* items; + Item *items; int expectedItemID = 1; int expectedSecondItemID = 2; @@ -25,7 +25,8 @@ void test_items(void) items = getItems("./src/content/items.map"); /* make visible OUTPUT */ - for(int i=0; i<4;i++){ + for (int i = 0; i < 4; i++) + { printf("%s\n", items[i].itemName); } @@ -35,4 +36,21 @@ void test_items(void) TEST_ASSERT_EQUAL_INT(expectedSecondItemID, items[1].id); } +void test_setItemPrice(void) +{ + + // arrange + int price = 50, result; + // act + Item test; + setItemPrice(&test, price); + result = test.price; + + printf("---------------------------------------------------\n"); + printf("setItemPrice | price to set: %d -> item.price: %d", price, result); + + // assert + TEST_ASSERT_EQUAL(price, result); +} + #endif // TEST