From 05dca15a6454e4cf3bce8745c396805842336491 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:55:57 +0100 Subject: [PATCH] added getItemPrice with test --- src/c/items.c | 6 +++++- src/c/items.h | 7 +++++-- test/c/test_items.c | 21 ++++++++++++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/c/items.c b/src/c/items.c index 7f09bd5..1b223fa 100644 --- a/src/c/items.c +++ b/src/c/items.c @@ -56,8 +56,12 @@ Item *getItems(char *itemsMapFile) return getItems; } +int getItemPrice(Item *item) +{ + return item->price; +} 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 143006f..0fa3740 100644 --- a/src/c/items.h +++ b/src/c/items.h @@ -2,7 +2,7 @@ #define ITEMS_H #define itemAttributesMax 4 // for items -#define maxItems 100 // for inventory/item list +#define maxItems 100 // for inventory/item list #include @@ -17,6 +17,9 @@ typedef struct Item *getItems(char *itemsMapFile); -void setItemPrice(Item* item, int price); +int getItemPrice(Item *item); +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 f9bf002..bfd4439 100644 --- a/test/c/test_items.c +++ b/test/c/test_items.c @@ -38,14 +38,15 @@ void test_items(void) void test_setItemPrice(void) { - // arrange int price = 50, result; + // act Item test; setItemPrice(&test, price); result = test.price; + //output printf("---------------------------------------------------\n"); printf("setItemPrice | price to set: %d -> item.price: %d", price, result); @@ -53,4 +54,22 @@ void test_setItemPrice(void) TEST_ASSERT_EQUAL(price, result); } + +void test_getItemPrice(void) +{ + // arrange + int price = 50, result; + + // act + Item test; + test.price = price; + result = getItemPrice(&test); + + //output + printf("getItemPrice | price should be: %d -> price is: %d", price, result); + + // assert + TEST_ASSERT_EQUAL(price, result); +} + #endif // TEST