Browse Source

Merge branch 'feature/balance-operations' of https://gitlab2.informatik.hs-fulda.de/fdai7057/bankmanagement-system into feature/balance-operations

remotes/origin/feature/loan-eligibility
Shivam Chaudhary 2 years ago
parent
commit
d66ad445d1
  1. 4
      src/CustomerData.txt
  2. 55
      src/sendmoney.c
  3. 10
      src/sendmoney.h
  4. 45
      src/updateCustomerAccountBalance.c
  5. 2
      src/updateCustomerAccountBalance.h
  6. 69
      tests/test_sendmoney.c

4
src/CustomerData.txt

@ -3,14 +3,14 @@ ID=1234
forename=Max
Surname=Mustermann
password=example
balance=2340
balance=2300
1327=example
ID=1327
forename=Max
Surname=Mustermann
password=example
balance=20
balance=160
1666=example
ID=1666

55
src/sendmoney.c

@ -0,0 +1,55 @@
#include "sendMoney.h"
#include "depositMoney.c"
#include "withdrawMoney.c"
bool sendMoney(int customerID){
float availableAccountBalance=getAvailableAccountBalance(customerID);
float amountToSend;
int recID;
printf("\nYou have %.2f€ in your account. How much would you like to send?\n",availableAccountBalance);
scanf("%f",&amountToSend);
if(amountToSend>0 && amountToSend<availableAccountBalance){
printf("\nYour input was %.2f€. Please enter the recipient id.\n",amountToSend);
scanf("%d",&recID);
if(recID>1000){
bool recExists=checkCustomerExists(recID);
if(recExists){
if(recID==customerID){
printf("\nYou cannot send money to yourself. Aborting. \n");
return false;
}
else{
if(withdrawSpecificAmount(customerID, amountToSend)){
if(depositSpecificAmount(recID, amountToSend)){
printf("\nYou have successfuly transfered %.2f€ to [%d]",amountToSend,recID);
return true;
}
else{
printf("\nSomething went wrong with the transfer. Please contact staff.");
}
}
}
}else{
if(withdrawSpecificAmount(customerID, amountToSend)){
printf("\nYou have successfuly transfered %.2f€ to [%d]",amountToSend,recID);
return true;
}
}
}
else
{
printf("\nThe ID you have entered is not valid. Aborting. \n");
}
}else{
//error
return false;
}
return false;
}
// int main(){
// sendMoney(1234);
// return 0;
// }

10
src/sendmoney.h

@ -0,0 +1,10 @@
#ifndef SENDMONEY_H
#define SENDMONEY_H
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
bool sendMoney(int customerID);
#endif // SENDMONEY_H

45
src/updateCustomerAccountBalance.c

@ -112,6 +112,51 @@ bool updateAvailableAccountBalance(int user_id, float newBalance){
}
return false;
}
bool checkCustomerExists(int customerID){
bool keep_reading = true;
bool customer_found=false;
char buffer[MAX_LENGTH];
char stringID[MAX_LENGTH] = "ID=";
char user_id_as_string[MAX_LENGTH];
char balance_String[MAX_LENGTH];
int currentLine=0;
sprintf(user_id_as_string, "%d", customerID); // converts user_id to string
strcat(stringID, user_id_as_string);
FILE *file = fopen(CUSTOMER_DATA_FILE, "r+");
if (file == NULL) {
return false;
}
while(keep_reading) {
fgets(buffer, MAX_LENGTH, file);
currentLine++;
if (feof(file)) {
keep_reading = false;
}
else if(strstr(buffer, stringID)) { //found the customer
for (int i = 0; i < 4; i++) {
fgets(buffer, MAX_LENGTH, file);
}
strcpy(balance_String, buffer);
currentLine+=4;
keep_reading = false;
customer_found=true;
}
}
fclose(file);;
if(customer_found){
return true;
}else{
return false;
}
return false;
}
//traditional testing section

2
src/updateCustomerAccountBalance.h

@ -9,7 +9,7 @@
bool updateAvailableAccountBalance(int user_id, float newBalance);
bool checkCustomerExists(int customerID);
void replaceBalanceInString(float replacementBalance, int currentLine);
#endif

69
tests/test_sendmoney.c

@ -0,0 +1,69 @@
#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
Loading…
Cancel
Save