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.

69 lines
1.3 KiB

  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "withdrawMoney.h"
  4. void setUp(void)
  5. {
  6. }
  7. void tearDown(void)
  8. {
  9. }
  10. void test_initiateWithdraw(void) {
  11. /* Arrange */
  12. int length = 10;
  13. float amountToWithdraw[] = {200.5, 340, 244.5, 340, 1200, 3232, 1123, 460.5, 900, 1005};
  14. float availableAccountBalance[] = {2000, 3400, 2445, 3400, 6000, 5000, 1000, 2000, 2000, 9000};
  15. float expectedValue[length];
  16. float result[length];
  17. /* Act */
  18. for (int i = 0; i < length; i++) {
  19. result[i] = initiateWithdraw( amountToWithdraw[i], availableAccountBalance[i] );
  20. }
  21. /* Assert */
  22. for (int i = 0; i < length; i++) {
  23. expectedValue[i] = ( availableAccountBalance[i] - amountToWithdraw[i] );
  24. }
  25. for (int i = 0; i < length; i++) {
  26. TEST_ASSERT_EQUAL_FLOAT(expectedValue[i],result[i]);
  27. }
  28. }
  29. void test_withdrawSpecificAmountSuccess(void) {
  30. /* Arrange */
  31. int user_id[3] = {1234, 1327, 1666}; // user_ids from file for testing
  32. bool result[3];
  33. /* Act */
  34. for (int i = 0; i < 3; i++) {
  35. result[i] = withdrawSpecificAmount(user_id[i], 50);
  36. }
  37. /* Assert */
  38. for (int i = 0; i < 3; i++) {
  39. TEST_ASSERT_TRUE(result[i]); // Pass if withdrawal is successful
  40. }
  41. }
  42. #endif // TEST