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.

93 lines
1.8 KiB

  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "../src/withdrawMoney.c"
  4. #include "../src/updateCustomerAccountBalance.c"
  5. #include "../src/currentCustomerAccountBalance.c"
  6. void setUp(void)
  7. {
  8. }
  9. void tearDown(void)
  10. {
  11. }
  12. void test_initiateWithdraw(void) {
  13. /* Arrange */
  14. int length = 10;
  15. float amountToWithdraw[] = {200.5, 340, 244.5, 340, 1200, 3232, 1123, 460.5, 900, 1005};
  16. float availableAccountBalance[] = {2000, 3400, 2445, 3400, 6000, 5000, 1000, 2000, 2000, 9000};
  17. float expectedValue[length];
  18. float result[length];
  19. /* Act */
  20. for (int i = 0; i < length; i++) {
  21. result[i] = initiateWithdraw( amountToWithdraw[i], availableAccountBalance[i] );
  22. }
  23. /* Assert */
  24. for (int i = 0; i < length; i++) {
  25. expectedValue[i] = ( availableAccountBalance[i] - amountToWithdraw[i] );
  26. }
  27. for (int i = 0; i < length; i++) {
  28. TEST_ASSERT_EQUAL_FLOAT(expectedValue[i],result[i]);
  29. }
  30. }
  31. void test_withdrawSpecificAmountSuccess(void) {
  32. /* Arrange */
  33. int user_id[3] = {1234, 1235, 1236}; // user_ids from file for testing
  34. bool result[3];
  35. /* Act */
  36. for (int i = 0; i < 3; i++) {
  37. result[i] = withdrawSpecificAmount(user_id[i], 50);
  38. }
  39. /* Assert */
  40. for (int i = 0; i < 3; i++) {
  41. TEST_ASSERT_TRUE(result[i]); // Pass if withdrawal is successful
  42. }
  43. }
  44. void test_withdrawSpecificAmountFailure(void) {
  45. /* Arrange */
  46. int user_id[3] = {12934, 13027, 16606}; // Random wrong user_ids
  47. bool result[3];
  48. /* Act */
  49. for (int i = 0; i < 3; i++) {
  50. result[i] = withdrawSpecificAmount(user_id[i], 50);
  51. }
  52. /* Assert */
  53. for (int i = 0; i < 3; i++) {
  54. TEST_ASSERT_FALSE(result[i]); // Pass if withdrawal fails and function returns false
  55. }
  56. }
  57. #endif // TEST