Browse Source

Integrate currency exchange to sendMoney

remotes/origin/feature/loan-eligibility
fdlt3817 2 years ago
parent
commit
d203a9156c
  1. 6
      src/depositMoney.c
  2. 56
      src/sendmoney.c
  3. 1
      src/sendmoney.h
  4. 69
      tests/test_sendmoney.c
  5. 14
      tests/test_updateCustomerAccountBalance.c

6
src/depositMoney.c

@ -25,13 +25,15 @@ void askToTryAgain(bool afterError, int customerID){
bool depositMoney(int customerID){ bool depositMoney(int customerID){
float availableAccountBalance=getAvailableAccountBalance(customerID); float availableAccountBalance=getAvailableAccountBalance(customerID);
if(availableAccountBalance<0){
printf("\nCould not retreive account balance. Please contact staff.\n");
}
float amountToDeposit = 0; float amountToDeposit = 0;
printf("\nPlease enter the amount you want to deposit: "); printf("\nPlease enter the amount you want to deposit: ");
scanf("%f", &amountToDeposit); scanf("%f", &amountToDeposit);
if(amountToDeposit>0 && amountToDeposit>MINIMUM_DEPOSIT_AMOUNT){
if(amountToDeposit>=0 && amountToDeposit>MINIMUM_DEPOSIT_AMOUNT){
if(updateAvailableAccountBalance(customerID, availableAccountBalance+amountToDeposit)){ if(updateAvailableAccountBalance(customerID, availableAccountBalance+amountToDeposit)){
printf("\nYou have successfully deposited %.2f. New account balance is %.2f", amountToDeposit, availableAccountBalance+amountToDeposit); printf("\nYou have successfully deposited %.2f. New account balance is %.2f", amountToDeposit, availableAccountBalance+amountToDeposit);
askToTryAgain(false,customerID); askToTryAgain(false,customerID);

56
src/sendmoney.c

@ -1,6 +1,7 @@
#include "sendMoney.h" #include "sendMoney.h"
#include "depositMoney.c" #include "depositMoney.c"
#include "withdrawMoney.c" #include "withdrawMoney.c"
#include "currencyExchange.c"
void showBalance(int customerID){ void showBalance(int customerID){
float balance=getAvailableAccountBalance(customerID); float balance=getAvailableAccountBalance(customerID);
@ -9,6 +10,47 @@ void showBalance(int customerID){
printf(":.:.:.:.:.:\n"); printf(":.:.:.:.:.:\n");
} }
float askToConvert(float input, int customerID){
char c;
char symbol[]="";
int id;
float converted;
printf("\nWould you like to convert the amount from € to another currency?[y] yes [any] no\n");
scanf(" %c",&c);
if(c=='y'||c=='Y'){
printf("\nPlease select from one of the following currencties to convert to:");
printf("\n[1] USD");
printf("\n[2] GBP");
printf("\n[3] YEN");
printf("\n[4] YUAN\n");
scanf("%d",&id);
if(id>0&&id<5){
converted=convert(input,id);
}else{
return 0;
}
switch(id){
case 1:
symbol[0]='$';
break;
case 2:
symbol[0]='P';
break;
case 3:
symbol[0]='Y';
break;
case 4:
symbol[0]='X';
break;
}
printf("\nYou have successfuly transfered %.2f%s to [%d]",converted, symbol,customerID);
return converted;
}else{
return 0;
}
}
void askToShowBalance(int customerID){ void askToShowBalance(int customerID){
char c; char c;
printf("\nWould you like to see your remaining balance? [y] yes [any] no\n"); printf("\nWould you like to see your remaining balance? [y] yes [any] no\n");
@ -40,7 +82,8 @@ bool sendMoney(int customerID){
else{ else{
if(withdrawSpecificAmount(customerID, amountToSend)){ if(withdrawSpecificAmount(customerID, amountToSend)){
if(depositSpecificAmount(recID, amountToSend)){ if(depositSpecificAmount(recID, amountToSend)){
printf("\nYou have successfuly transfered %.2f€ to [%d]",amountToSend,recID);
askToConvert(amountToSend, recID);
//printf("\nYou have successfuly transfered %.2f€ to [%d]",amountToSend,recID);
askToShowBalance(customerID); askToShowBalance(customerID);
return true; return true;
} }
@ -53,7 +96,8 @@ bool sendMoney(int customerID){
}else{ }else{
printf("\nThis ID is not from a customer of our bank. A transfer fee of %.2f€ will be taken.\n", TRANSFER_FEE); printf("\nThis ID is not from a customer of our bank. A transfer fee of %.2f€ will be taken.\n", TRANSFER_FEE);
if(withdrawSpecificAmount(customerID, amountToSend+TRANSFER_FEE)){ if(withdrawSpecificAmount(customerID, amountToSend+TRANSFER_FEE)){
printf("\nYou have successfuly transfered %.2f€ to [%d]\n",amountToSend,recID);
askToConvert(amountToSend, recID);
//printf("\nYou have successfuly transfered %.2f€ to [%d]\n",amountToSend,recID);
askToShowBalance(customerID); askToShowBalance(customerID);
return true; return true;
} }
@ -71,7 +115,7 @@ bool sendMoney(int customerID){
return false; return false;
} }
// int main(){
// sendMoney(1234);
// return 0;
// }
int main(){
sendMoney(1234);
return 0;
}

1
src/sendmoney.h

@ -7,6 +7,7 @@
#define TRANSFER_FEE 0.8 #define TRANSFER_FEE 0.8
void showBalance(int customerID); void showBalance(int customerID);
float askToConvert(float input, int customerID);
void askToShowBalance(int customerID); void askToShowBalance(int customerID);
bool sendMoney(int customerID); bool sendMoney(int customerID);

69
tests/test_sendmoney.c

@ -1,69 +0,0 @@
#ifdef TEST
#include <sendmoney.h>
#include <unity.h>
void setUp(void)
{
}
void tearDown(void)
{
}
// hier wird die Methode checkAccount getestet
void test_sendmoney_NeedToImplement(void)
{
// Arrage
int accountNumber = 1234567;
int accountNumber2 = 5555557;
// hier soll false sein
int accountNumber3 = 53323;
int accountNumber4 = 34342;
bool expected;
bool expected2;
bool expected3;
bool expected4;
// Act
expected = checkAccount(accountNumber);
expected2 = checkAccount(accountNumber2);
expected3 = checkAccount(accountNumber3);
expected4 = checkAccount(accountNumber4);
// Assert
TEST_ASSERT_TRUE(expected);
TEST_ASSERT_TRUE(expected2);
TEST_ASSERT_FALSE(expected3);
TEST_ASSERT_FALSE(expected4);
}
// hier wird die Methode getAvailableAccountBalance()getestet
void test_getAvailableAccountBalance(void)
{
// Arrage
double expected1 = 24.0;
int length = 2;
// Act
double result = getAvailableAccountBalance(length);
// Assert
TEST_ASSERT_EQUAL(expected1, result);
}
// hier wird die Methode getAmount() getestet
void test_getAmount(void)
{
// Arrage
float expected = 500.1;
float result = getAmount(expected);
TEST_ASSERT_EQUAL(expected, result);
}
#endif // TEST

14
tests/test_updateCustomerAccountBalance.c

@ -34,13 +34,13 @@ void test_updateAvailableAccountBalanceSuccess(void){
/* Arrange */ /* Arrange */
int length = 10;
int length = 5;
float amountToUpdate[] = {200.5, 340, 244.5, 340, 1200, 3232, 1123, 460.5, 900, 1005};
float userIDs[] = {1001,1002,1003,1004,1005,1006,1007,1008,1009,1010};
float amountToUpdate[] = {200.5, 340, 244.5, 340, 1200};
int userIDs[] = {1234,1235,1236,1237,1238};
float expectedValue[length]; float expectedValue[length];
float result[length];
bool result[length];
/* Act */ /* Act */
@ -51,11 +51,7 @@ void test_updateAvailableAccountBalanceSuccess(void){
/* Assert */ /* Assert */
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
expectedValue[i] = amountToUpdate[i];
}
for (int i = 0; i < length; i++) {
TEST_ASSERT_EQUAL_FLOAT(expectedValue[i],result[i]);
TEST_ASSERT_TRUE(result[i]);
} }
} }

Loading…
Cancel
Save