diff --git a/src/_file_information.h b/src/_file_information.h index 1cb5200..22c8af6 100644 --- a/src/_file_information.h +++ b/src/_file_information.h @@ -1,2 +1,2 @@ #define MAX_LENGTH 100 -#define CUSTOMER_DATA_FILE "CustomerData.txt" \ No newline at end of file +#define CUSTOMER_DATA_FILE "src/CustomerData.txt" \ No newline at end of file diff --git a/src/currentCustomerAccountBalance.c b/src/currentCustomerAccountBalance.c index a91e306..d306175 100644 --- a/src/currentCustomerAccountBalance.c +++ b/src/currentCustomerAccountBalance.c @@ -1,4 +1,5 @@ #include "currentCustomerAccountBalance.h" +#include "_file_information.h" float fetchBalanceFromBalanceString(char balance_String[MAX_LENGTH]) { float balance = 0; diff --git a/tests/test_currentCustomerAccountBalance.c b/tests/test_currentCustomerAccountBalance.c new file mode 100644 index 0000000..4855135 --- /dev/null +++ b/tests/test_currentCustomerAccountBalance.c @@ -0,0 +1,72 @@ +#ifdef TEST + +#include +#include "unity.h" +#include "currentCustomerAccountBalance.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_fetchBalanceFromBalanceString(void) { + char balanceString[5][100] = { + "balance=0", + "balance=100", + "balance=200", + "balance=300", + "balance=400" + }; + + float balance = 0; + float result[5]; + float expected[5]; + + for (int i = 0; i < 5; i++) { + result[i] = fetchBalanceFromBalanceString(balanceString[i]); + } + + for (int i = 0; i < 5; i++) { + expected[i] = balance; + balance += 100; + } + + for (int i =0; i < 5; i++) { + TEST_ASSERT_EQUAL_FLOAT(expected[i],result[i]); + } + + +} + + +void test_checkFileOpen(void) { + + FILE *file = fopen(CUSTOMER_DATA_FILE, "r"); + + TEST_ASSERT_TRUE(file); + + fclose(file); +} + +void test_failOpenFile(void) { + FILE *file = fopen("false_file_name", "r"); + + TEST_ASSERT_FALSE(file); + +} + +void test_getAvailableAccountBalance(void) { + int user_id = 1234; + float max = FLT_MAX; + int result = getAvailableAccountBalance(user_id); + + TEST_ASSERT_TRUE(result < max); +} + + + + +#endif // TEST