Browse Source

Fix header problems and add depositSpecificAmount function

remotes/origin/feature/loan-eligibility
fdlt3817 2 years ago
parent
commit
b7bee9c73d
  1. 2
      src/_file_information.h
  2. 1
      src/currentCustomerAccountBalance.c
  3. 6
      src/currentCustomerAccountBalance.h
  4. 20
      src/depositMoney.c
  5. 3
      src/depositMoney.h
  6. 5
      src/updateCustomerAccountBalance.h
  7. 21
      tests/test_LoginCustomer.c
  8. 145
      tests/test_mainMenu.c

2
src/_file_information.h

@ -1,2 +1,2 @@
#define MAX_LENGTH 200 #define MAX_LENGTH 200
#define CUSTOMER_DATA_FILE "CustomerData.txt"
#define CUSTOMER_DATA_FILE "src/CustomerData.txt"

1
src/currentCustomerAccountBalance.c

@ -1,4 +1,5 @@
#include "currentCustomerAccountBalance.h" #include "currentCustomerAccountBalance.h"
#include "_file_information.h"
float fetchBalanceFromBalanceString(char balance_String[MAX_LENGTH]) { float fetchBalanceFromBalanceString(char balance_String[MAX_LENGTH]) {
float balance = 0; float balance = 0;

6
src/currentCustomerAccountBalance.h

@ -1,3 +1,7 @@
#ifndef CURRENTCUSTOMERACCOUNTBALANCE_H_
#define CURRENTCUSTOMERACCOUNTBALANCE_H_
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
@ -8,3 +12,5 @@
float getAvailableAccountBalance(int user_id); float getAvailableAccountBalance(int user_id);
float fetchBalanceFromBalanceString(char balance_String[MAX_LENGTH]); float fetchBalanceFromBalanceString(char balance_String[MAX_LENGTH]);
float readFileAndGetAvailableBalance(FILE *file, char stringID[MAX_LENGTH]); float readFileAndGetAvailableBalance(FILE *file, char stringID[MAX_LENGTH]);
#endif

20
src/depositMoney.c

@ -1,5 +1,6 @@
#include "depositMoney.h" #include "depositMoney.h"
#include "updateCustomerAccountBalance.c"
#include "updateCustomerAccountBalance.h"
#include "currentCustomerAccountBalance.h"
void askToTryAgain(bool afterError, int customerID){ void askToTryAgain(bool afterError, int customerID){
char choice; char choice;
@ -51,9 +52,24 @@ bool depositMoney(int customerID){
return false; return false;
} }
bool depositSpecificAmount(int customerID, float amount){
float availableAccountBalance=getAvailableAccountBalance(customerID);
if(amount>0){
if(updateAvailableAccountBalance(customerID, availableAccountBalance+amount)){
return true;
}else{
return false;
}
}
return false;
}
/* /*
int main(){ int main(){
depositMoney(1234);
depositSpecificAmount(1234,5000);
//depositMoney(1234);
return 0; return 0;
} }
*/ */

3
src/depositMoney.h

@ -1,3 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include "CustomerProperties.h" #include "CustomerProperties.h"
#include <stdbool.h> #include <stdbool.h>
@ -6,3 +8,4 @@
bool depositMoney(int customerID); bool depositMoney(int customerID);
void askToTryAgain(bool afterError, int customerID); void askToTryAgain(bool afterError, int customerID);
bool depositSpecificAmount(int customerID, float amount);

5
src/updateCustomerAccountBalance.h

@ -1,3 +1,6 @@
#ifndef UPDATECUSTOMERACCOUNTBALANCE_H_
#define UPDATECUSTOMERACCOUNTBALANCE_H_
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
@ -8,3 +11,5 @@
bool updateAvailableAccountBalance(int user_id, float newBalance); bool updateAvailableAccountBalance(int user_id, float newBalance);
void replaceBalanceInString(float replacementBalance, int currentLine); void replaceBalanceInString(float replacementBalance, int currentLine);
#endif

21
tests/test_LoginCustomer.c

@ -1,21 +0,0 @@
#include <unity.h>
#include "LoginCustomer.h"
void setUp(){};
void tearDown(){};
void test_checkLogin()
{
/*arrange*/
bool expected_test_values_compute_to_true[] = {4==4,true==true, 1==1, false==false, 'z'=='z', '='=='=',0x1A==0x1A};
int length_1 = sizeof(expected_test_values_compute_to_true)/sizeof(bool);
bool expected_test_values_compute_to_false[] = {4!=4,true==false,1==0,false==true,'z'=='x','!'==')',0x1A==0x2B};
int length_2 = sizeof(expected_test_values_compute_to_false)/sizeof(bool);
/*act and assertions*/
for(int i=0;i<7;++i) {
TEST_ASSERT_TRUE(checkLogin(expected_test_values_compute_to_true[i]));
}
for(int i=0;i<7;++i){
TEST_ASSERT_FALSE(checkLogin(expected_test_values_compute_to_false[i]));
}
}

145
tests/test_mainMenu.c

@ -1,145 +0,0 @@
#ifdef TEST
#include "unity.h"
#include "mainMenu.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void test_agePermissionValidAge(void)
{
//Test case : 0
//Arrange
int validAge[83];
bool validAgeResult[83];
int j=0;
for(int i =18;i<101;i++){
validAge[j]= i;
j++;
}
//Act
for(int i=0;i<83;i++){
validAgeResult[i] = agePermission(validAge[i]);
}
//Assert
for(int i=0;i<83;i++){
TEST_ASSERT_TRUE(validAgeResult[i]);
}
}
void test_agePermissionInvalidAge(void)
{
//Test case : 1
//Arrange
int invalidAge[117];
bool invalidAgeResult[117];
int j=0;
for(int i =-100;i<18;i++){
invalidAge[j]= i;
j++;
}
//Act
for(int i=0;i<117;i++){
invalidAgeResult[i] = agePermission(invalidAge[i]);
}
//Assert
for(int i=0;i<117;i++){
TEST_ASSERT_FALSE(invalidAgeResult[i]);
}
}
void test_IsInteger(void)
{
//Arrange
char* inputIsInteger[] = {"-10000000","-2000000","-354698","-66667","-7878","-987","-64","-5","0","1","2","10","201","333","4321","56974","698751","7878989","88954621" };
bool inputIsIntegerResult[19];
//Act
for(int i=0;i<19;i++)
{
inputIsIntegerResult[i] = checkIfInteger(inputIsInteger[i]);
}
//Assert
for(int i=0;i<19;i++)
{
TEST_ASSERT_TRUE(inputIsIntegerResult[i]);
}
}
void test_IsNotInteger(void)
{
//Arrange
char* inputIsNotInteger[] = {"0.15","3.141592653589793238","5.3254f","-6.264","-7878.3261","foo","Bar","FIZZ","buzZ","joHN","jAnE","foo-bar","3,15","2k13",""," ","-","+","/*-+.,/=" };
bool inputIsNotIntegerResult[19];
//Act
for(int i=0;i<19;i++)
{
inputIsNotIntegerResult[i] = checkIfInteger(inputIsNotInteger[i]);
}
//Assert
for(int i=0;i<19;i++)
{
TEST_ASSERT_FALSE(inputIsNotIntegerResult[i]);
}
}
#endif // TEST
Loading…
Cancel
Save