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.

72 lines
1.2 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. char balanceString[5][100] = {
  13. "balance=0",
  14. "balance=100",
  15. "balance=200",
  16. "balance=300",
  17. "balance=400"
  18. };
  19. float balance = 0;
  20. float result[5];
  21. float expected[5];
  22. for (int i = 0; i < 5; i++) {
  23. result[i] = fetchBalanceFromBalanceString(balanceString[i]);
  24. }
  25. for (int i = 0; i < 5; i++) {
  26. expected[i] = balance;
  27. balance += 100;
  28. }
  29. for (int i =0; i < 5; i++) {
  30. TEST_ASSERT_EQUAL_FLOAT(expected[i],result[i]);
  31. }
  32. }
  33. void test_checkFileOpen(void) {
  34. FILE *file = fopen(CUSTOMER_DATA_FILE, "r");
  35. TEST_ASSERT_TRUE(file);
  36. fclose(file);
  37. }
  38. void test_failOpenFile(void) {
  39. FILE *file = fopen("false_file_name", "r");
  40. TEST_ASSERT_FALSE(file);
  41. }
  42. void test_getAvailableAccountBalance(void) {
  43. int user_id = 1234;
  44. float max = FLT_MAX;
  45. int result = getAvailableAccountBalance(user_id);
  46. TEST_ASSERT_TRUE(result < max);
  47. }
  48. #endif // TEST