Browse Source

added setItemPrice with test

remotes/origin/navigation
KRUGSON 2 years ago
parent
commit
218a01068d
  1. 6
      src/c/items.c
  2. 2
      src/c/items.h
  3. 22
      test/c/test_items.c

6
src/c/items.c

@ -55,3 +55,9 @@ Item *getItems(char *itemsMapFile)
} }
return getItems; return getItems;
} }
void setItemPrice(Item* item, int price)
{
item->price = price;
}

2
src/c/items.h

@ -17,4 +17,6 @@ typedef struct
Item *getItems(char *itemsMapFile); Item *getItems(char *itemsMapFile);
void setItemPrice(Item* item, int price);
#endif #endif

22
test/c/test_items.c

@ -16,7 +16,7 @@ void test_items(void)
{ {
/* arrange */ /* arrange */
// Hier die Werte eingeben/deklarieren // Hier die Werte eingeben/deklarieren
Item* items;
Item *items;
int expectedItemID = 1; int expectedItemID = 1;
int expectedSecondItemID = 2; int expectedSecondItemID = 2;
@ -25,7 +25,8 @@ void test_items(void)
items = getItems("./src/content/items.map"); items = getItems("./src/content/items.map");
/* make visible OUTPUT */ /* make visible OUTPUT */
for(int i=0; i<4;i++){
for (int i = 0; i < 4; i++)
{
printf("%s\n", items[i].itemName); printf("%s\n", items[i].itemName);
} }
@ -35,4 +36,21 @@ void test_items(void)
TEST_ASSERT_EQUAL_INT(expectedSecondItemID, items[1].id); 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 #endif // TEST
Loading…
Cancel
Save