Browse Source

added getItemPrice with test

remotes/origin/navigation
KRUGSON 2 years ago
parent
commit
05dca15a64
  1. 6
      src/c/items.c
  2. 7
      src/c/items.h
  3. 21
      test/c/test_items.c

6
src/c/items.c

@ -56,8 +56,12 @@ Item *getItems(char *itemsMapFile)
return getItems; return getItems;
} }
int getItemPrice(Item *item)
{
return item->price;
}
void setItemPrice(Item* item, int price) void setItemPrice(Item* item, int price)
{ {
item->price = price; item->price = price;
}
}

7
src/c/items.h

@ -2,7 +2,7 @@
#define ITEMS_H #define ITEMS_H
#define itemAttributesMax 4 // for items #define itemAttributesMax 4 // for items
#define maxItems 100 // for inventory/item list
#define maxItems 100 // for inventory/item list
#include <stdbool.h> #include <stdbool.h>
@ -17,6 +17,9 @@ typedef struct
Item *getItems(char *itemsMapFile); Item *getItems(char *itemsMapFile);
void setItemPrice(Item* item, int price);
int getItemPrice(Item *item);
void setItemPrice(Item *item, int price);
#endif #endif

21
test/c/test_items.c

@ -38,14 +38,15 @@ void test_items(void)
void test_setItemPrice(void) void test_setItemPrice(void)
{ {
// arrange // arrange
int price = 50, result; int price = 50, result;
// act // act
Item test; Item test;
setItemPrice(&test, price); setItemPrice(&test, price);
result = test.price; result = test.price;
//output
printf("---------------------------------------------------\n"); printf("---------------------------------------------------\n");
printf("setItemPrice | price to set: %d -> item.price: %d", price, result); printf("setItemPrice | price to set: %d -> item.price: %d", price, result);
@ -53,4 +54,22 @@ void test_setItemPrice(void)
TEST_ASSERT_EQUAL(price, result); 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 #endif // TEST
Loading…
Cancel
Save