You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
1.4 KiB

  1. #ifdef TEST
  2. #include <float.h>
  3. #include "unity.h"
  4. #include "currentCustomerAccountBalance.h"
  5. void setUp(void)
  6. {
  7. }
  8. void tearDown(void)
  9. {
  10. }
  11. void test_fetchBalanceFromBalanceString(void) {
  12. /* Arrange */
  13. char balanceString[5][100] = {
  14. "balance=0",
  15. "balance=100",
  16. "balance=200",
  17. "balance=300",
  18. "balance=400"
  19. };
  20. /* Act */
  21. float balance = 0;
  22. float result[5];
  23. float expected[5];
  24. for (int i = 0; i < 5; i++) {
  25. result[i] = fetchBalanceFromBalanceString(balanceString[i]);
  26. }
  27. /* Assert */
  28. for (int i = 0; i < 5; i++) {
  29. expected[i] = balance;
  30. balance += 100;
  31. }
  32. for (int i =0; i < 5; i++) {
  33. TEST_ASSERT_EQUAL_FLOAT(expected[i],result[i]);
  34. }
  35. }
  36. void test_checkFileOpen(void) {
  37. /* Act and assert */
  38. FILE *file = fopen(CUSTOMER_DATA_FILE, "r");
  39. TEST_ASSERT_TRUE(file);
  40. fclose(file);
  41. }
  42. void test_failOpenFile(void) {
  43. /* Act and assert */
  44. FILE *file = fopen("false_file_name", "r");
  45. TEST_ASSERT_FALSE(file);
  46. }
  47. void test_getAvailableAccountBalance(void) {
  48. /* Act and assert */
  49. int user_id = 1234; // Random user_id (because idea is to read the file and get a float value)
  50. float max = FLT_MAX;
  51. int result = getAvailableAccountBalance(user_id);
  52. TEST_ASSERT_TRUE(result < max); // Pass if function is successfully called and a float value (balance) is returned
  53. }
  54. #endif // TEST