#ifdef TEST #include #include "unity.h" #include "../src/currentCustomerAccountBalance.c" void setUp(void) { } void tearDown(void) { } void test_fetchBalanceFromBalanceString(void) { /* Arrange */ char balanceString[5][100] = { "balance=0", "balance=100", "balance=200", "balance=300", "balance=400" }; /* Act */ float balance = 0; float result[5]; float expected[5]; for (int i = 0; i < 5; i++) { result[i] = fetchBalanceFromBalanceString(balanceString[i]); } /* Assert */ 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) { /* Act and assert */ FILE *file = fopen(CUSTOMER_DATA_FILE, "r"); TEST_ASSERT_TRUE(file); fclose(file); } void test_failOpenFile(void) { /* Act and assert */ FILE *file = fopen("false_file_name", "r"); TEST_ASSERT_FALSE(file); } void test_getAvailableAccountBalance(void) { /* Act and assert */ int user_id = 1234; // Random user_id (because idea is to read the file and get a float value) float max = FLT_MAX; int result = getAvailableAccountBalance(user_id); TEST_ASSERT_TRUE(result < max); // Pass if function is successfully called and a float value (balance) is returned } #endif // TEST