fdlt3817
2 years ago
92 changed files with 5059 additions and 11 deletions
-
7.gitignore
-
51build-project.sh
-
126project.yml
-
21src/.vscode/c_cpp_properties.json
-
69src/CustomerData.txt
-
2src/_file_information.h
-
12src/calculatorAdd.c
-
3src/calculatorAdd.h
-
11src/calculatorDivide.c
-
3src/calculatorDivide.h
-
18src/calculatorFactorial.c
-
3src/calculatorFactorial.h
-
26src/calculatorGetUserInput.c
-
5src/calculatorGetUserInput.h
-
22src/calculatorGetUserInputFactorial.c
-
4src/calculatorGetUserInputFactorial.h
-
10src/calculatorMultiply.c
-
3src/calculatorMultiply.h
-
12src/calculatorSubtract.c
-
4src/calculatorSubtract.h
-
30src/checkLoanEligibility.c
-
10src/checkLoanEligibility.h
-
129src/createCustomer.c
-
13src/createCustomer.h
-
234src/createEmployeeAccount.c
-
39src/createEmployeeAccount.h
-
20src/currencyExchange.c
-
18src/currencyExchange.h
-
65src/currentCustomerAccountBalance.c
-
16src/currentCustomerAccountBalance.h
-
78src/customerMenu.c
-
7src/customerMenu.h
-
11src/customerProperties.h
-
71src/depositMoney.c
-
9src/depositMoney.h
-
20src/displayDisclaimer.c
-
7src/displayDisclaimer.h
-
88src/displayMenuCalculator.c
-
4src/displayMenuCalculator.h
-
14src/docs.txt
-
139src/employeeLogin.c
-
19src/employeeLogin.h
-
20src/employeesCredentialsList.txt
-
52src/employeesData.txt
-
59src/error.c
-
3src/error.h
-
151src/helperFunctions.c
-
18src/helperFunctions.h
-
162src/interestCalculator.c
-
11src/interestCalculator.h
-
11src/lineReplacer.h
-
88src/loginCustomer.c
-
15src/loginCustomer.h
-
15src/main.c
-
152src/mainMenu.c
-
22src/mainMenu.h
-
29src/requestLoan.c
-
5src/requestLoan.h
-
112src/sendMoney.c
-
14src/sendMoney.h
-
131src/showGeneralInfoEmployee.c
-
12src/showGeneralInfoEmployee.h
-
169src/updateCustomerAccountBalance.c
-
15src/updateCustomerAccountBalance.h
-
102src/withdrawMoney.c
-
14src/withdrawMoney.h
-
7team.md
-
0tests/support/.gitkeep
-
29tests/test_CreateCustomer.c
-
81tests/test_Error.c
-
32tests/test_LoginCustomer.c
-
122tests/test_calculatorAdd.c
-
117tests/test_calculatorDivide.c
-
79tests/test_calculatorFactorial.c
-
25tests/test_calculatorGetUserInput.c
-
27tests/test_calculatorGetUserInputFactorial.c
-
120tests/test_calculatorMultiply.c
-
121tests/test_calculatorSubtract.c
-
57tests/test_checkLoanEligibility.c
-
304tests/test_createEmployeeAccount.c
-
58tests/test_currencyExchange.c
-
87tests/test_currentCustomerAccountBalance.c
-
36tests/test_depositMoney.c
-
31tests/test_displayMenuCalculator.c
-
147tests/test_employeeLogin.c
-
213tests/test_helperFunctions.c
-
50tests/test_interestCalculator.c
-
246tests/test_mainMenu.c
-
23tests/test_requestLoan.c
-
63tests/test_showGeneralInfoEmployee.c
-
67tests/test_updateCustomerAccountBalance.c
-
93tests/test_withdrawMoney.c
@ -1,2 +1,5 @@ |
|||||
.DS_Store |
|
||||
.swp |
|
||||
|
*.DS_Store |
||||
|
*.vscode |
||||
|
a.out |
||||
|
build/ |
||||
|
*.DSYM |
@ -1,5 +1,54 @@ |
|||||
|
trap 'echo "Interrupted"; |
||||
|
rm main; |
||||
|
cp employeeLogin.c.bak employeeLogin.c; |
||||
|
cp mainMenu.c.bak mainMenu.c; |
||||
|
cp createEmployeeAccount.c.bak createEmployeeAccount.c; |
||||
|
cp _file_information.h.bak _file_information.h; |
||||
|
rm employeeLogin.c.bak; |
||||
|
rm mainMenu.c.bak; |
||||
|
rm createEmployeeAccount.c.bak; |
||||
|
rm _file_information.h.bak; |
||||
|
cd ..; |
||||
|
rm -r build; exit' SIGINT |
||||
|
|
||||
clear |
clear |
||||
|
ceedling test:all |
||||
|
rm -r build/ |
||||
|
|
||||
|
|
||||
cd src/ |
cd src/ |
||||
gcc main.c -o main |
|
||||
|
|
||||
|
sed '/John Doe/,$d' employeesCredentialsList.txt > temp.txt |
||||
|
mv temp.txt employeesCredentialsList.txt |
||||
|
|
||||
|
sed '/Name : John/,$d' employeesData.txt > temp.txt |
||||
|
mv temp.txt employeesData.txt |
||||
|
|
||||
|
# backup files |
||||
|
for file in employeeLogin.c mainMenu.c createEmployeeAccount.c _file_information.h; do |
||||
|
cp "$file" "$file.bak" |
||||
|
done |
||||
|
|
||||
|
|
||||
|
# remove 'src/' |
||||
|
for file in employeeLogin.c createEmployeeAccount.c _file_information.h; do |
||||
|
sed -i 's/src\///g' "$file" |
||||
|
done |
||||
|
|
||||
|
|
||||
|
gcc mainMenu.c error.c createEmployeeAccount.c showGeneralInfoEmployee.c employeeLogin.c createCustomer.c helperFunctions.c loginCustomer.c customerMenu.c main.c calculatorAdd.c calculatorDivide.c calculatorFactorial.c calculatorGetUserInput.c calculatorGetUserInputFactorial.c calculatorMultiply.c calculatorSubtract.c displayMenuCalculator.c checkLoanEligibility.c currencyExchange.c currentCustomerAccountBalance.c depositMoney.c displayDisclaimer.c interestCalculator.c requestLoan.c sendMoney.c updateCustomerAccountBalance.c withdrawMoney.c -o main |
||||
./main |
./main |
||||
rm main |
rm main |
||||
|
|
||||
|
# restore backups |
||||
|
for file in employeeLogin.c mainMenu.c createEmployeeAccount.c _file_information.h; do |
||||
|
cp "$file.bak" "$file" |
||||
|
done |
||||
|
|
||||
|
# remove backups |
||||
|
for file in employeeLogin.c.bak mainMenu.c.bak createEmployeeAccount.c.bak _file_information.h.bak; do |
||||
|
rm "$file" |
||||
|
done |
||||
|
|
||||
|
|
||||
|
cd .. |
@ -0,0 +1,126 @@ |
|||||
|
--- |
||||
|
|
||||
|
# Notes: |
||||
|
# Sample project C code is not presently written to produce a release artifact. |
||||
|
# As such, release build options are disabled. |
||||
|
# This sample, therefore, only demonstrates running a collection of unit tests. |
||||
|
|
||||
|
:project: |
||||
|
:use_exceptions: FALSE |
||||
|
:use_test_preprocessor: TRUE |
||||
|
:use_auxiliary_dependencies: TRUE |
||||
|
:build_root: build |
||||
|
# :release_build: TRUE |
||||
|
:test_file_prefix: test_ |
||||
|
:which_ceedling: gem |
||||
|
:ceedling_version: 0.31.1 |
||||
|
:default_tasks: |
||||
|
- test:all |
||||
|
|
||||
|
#:test_build: |
||||
|
# :use_assembly: TRUE |
||||
|
|
||||
|
#:release_build: |
||||
|
# :output: MyApp.out |
||||
|
# :use_assembly: FALSE |
||||
|
|
||||
|
:environment: |
||||
|
|
||||
|
:extension: |
||||
|
:executable: .out |
||||
|
|
||||
|
:paths: |
||||
|
:test: |
||||
|
- +:tests/** |
||||
|
- -:tests/support |
||||
|
- +:tests/** |
||||
|
- -:tests/support |
||||
|
:source: |
||||
|
- src/createCustomer.* |
||||
|
- src/customerLogin.* |
||||
|
- src/helperFunctions.* |
||||
|
- src/error.* |
||||
|
- src/createEmployeeAccount.* |
||||
|
- src/employeeLogin.* |
||||
|
- src/mainMenu.* |
||||
|
- src/showGeneralInfoEmployee.* |
||||
|
- src/calculatorAdd.* |
||||
|
- src/calculatorDivide.* |
||||
|
- src/calculatorFactorial.* |
||||
|
- src/calculatorGetUserInput.* |
||||
|
- src/calculatorGetUserInputFactorial.* |
||||
|
- src/calculatorMultiply.* |
||||
|
- src/calculatorSubtract.* |
||||
|
- src/displayMenuCalculator.* |
||||
|
- src/requestLoan.* |
||||
|
- src/checkLoanEligibility.* |
||||
|
- src/currenczExchange.* |
||||
|
- src/currentCustomerAccountBalance.* |
||||
|
- src/depositMoney.* |
||||
|
- src/displayDisclaimer.* |
||||
|
- src/sendMoney.* |
||||
|
:support: |
||||
|
- tests/support |
||||
|
- tests/support |
||||
|
:libraries: [] |
||||
|
|
||||
|
:defines: |
||||
|
# in order to add common defines: |
||||
|
# 1) remove the trailing [] from the :common: section |
||||
|
# 2) add entries to the :common: section (e.g. :test: has TEST defined) |
||||
|
:common: &common_defines [] |
||||
|
:test: |
||||
|
- *common_defines |
||||
|
- TEST |
||||
|
:test_preprocess: |
||||
|
- *common_defines |
||||
|
- TEST |
||||
|
|
||||
|
:cmock: |
||||
|
:mock_prefix: mock_ |
||||
|
:when_no_prototypes: :warn |
||||
|
:enforce_strict_ordering: TRUE |
||||
|
:plugins: |
||||
|
- :ignore |
||||
|
- :callback |
||||
|
:treat_as: |
||||
|
uint8: HEX8 |
||||
|
uint16: HEX16 |
||||
|
uint32: UINT32 |
||||
|
int8: INT8 |
||||
|
bool: UINT8 |
||||
|
|
||||
|
# Add -gcov to the plugins list to make sure of the gcov plugin |
||||
|
# You will need to have gcov and gcovr both installed to make it work. |
||||
|
# For more information on these options, see docs in plugins/gcov |
||||
|
:gcov: |
||||
|
:reports: |
||||
|
- HtmlDetailed |
||||
|
:gcovr: |
||||
|
:html_medium_threshold: 75 |
||||
|
:html_high_threshold: 90 |
||||
|
|
||||
|
#:tools: |
||||
|
# Ceedling defaults to using gcc for compiling, linking, etc. |
||||
|
# As [:tools] is blank, gcc will be used (so long as it's in your system path) |
||||
|
# See documentation to configure a given toolchain for use |
||||
|
|
||||
|
# LIBRARIES |
||||
|
# These libraries are automatically injected into the build process. Those specified as |
||||
|
# common will be used in all types of builds. Otherwise, libraries can be injected in just |
||||
|
# tests or releases. These options are MERGED with the options in supplemental yaml files. |
||||
|
:libraries: |
||||
|
:placement: :end |
||||
|
:flag: "-l${1}" |
||||
|
:path_flag: "-L ${1}" |
||||
|
:system: [] # for example, you might list 'm' to grab the math library |
||||
|
:test: [] |
||||
|
:release: [] |
||||
|
|
||||
|
:plugins: |
||||
|
:load_paths: |
||||
|
- "#{Ceedling.load_path}" |
||||
|
:enabled: |
||||
|
- stdout_pretty_tests_report |
||||
|
- module_generator |
||||
|
... |
@ -0,0 +1,21 @@ |
|||||
|
{ |
||||
|
"configurations": [ |
||||
|
{ |
||||
|
"name": "Win32", |
||||
|
"includePath": [ |
||||
|
"${workspaceFolder}/**" |
||||
|
], |
||||
|
"defines": [ |
||||
|
"_DEBUG", |
||||
|
"UNICODE", |
||||
|
"_UNICODE" |
||||
|
], |
||||
|
"windowsSdkVersion": "10.0.19041.0", |
||||
|
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe", |
||||
|
"cStandard": "c17", |
||||
|
"cppStandard": "c++17", |
||||
|
"intelliSenseMode": "windows-msvc-x64" |
||||
|
} |
||||
|
], |
||||
|
"version": 4 |
||||
|
} |
@ -0,0 +1,69 @@ |
|||||
|
1234=example |
||||
|
ID=1234 |
||||
|
forename=Test |
||||
|
Surname=Testermann |
||||
|
password=example |
||||
|
balance=150.5 |
||||
|
|
||||
|
1235=example |
||||
|
ID=1235 |
||||
|
forename=Test |
||||
|
Surname=Testermann |
||||
|
password=example |
||||
|
balance=290 |
||||
|
|
||||
|
1236=example |
||||
|
ID=1236 |
||||
|
forename=Test |
||||
|
Surname=Testermann |
||||
|
password=example |
||||
|
balance=194.5 |
||||
|
|
||||
|
1237=example |
||||
|
ID=1237 |
||||
|
forename=Test |
||||
|
Surname=Testermann |
||||
|
password=example |
||||
|
balance=340 |
||||
|
|
||||
|
1238=example |
||||
|
ID=1238 |
||||
|
forename=Test |
||||
|
Surname=Testermann |
||||
|
password=example |
||||
|
balance=1200 |
||||
|
|
||||
|
1666=example |
||||
|
ID=1237 |
||||
|
forename=Test |
||||
|
Surname=Testermann |
||||
|
password=example |
||||
|
balance=340 |
||||
|
|
||||
|
1327=example |
||||
|
ID=1238 |
||||
|
forename=Test |
||||
|
Surname=Testermann |
||||
|
password=example |
||||
|
balance=1200 |
||||
|
2189837=1234 |
||||
|
ID=2189837 |
||||
|
Forename=Mark |
||||
|
Surname=Karlsen |
||||
|
Password=1234 |
||||
|
Balance=50.0000€ |
||||
|
|
||||
|
6984947=okdsjhasdjhksdj |
||||
|
ID=6984947 |
||||
|
Forename=Karl |
||||
|
Surname=Marx |
||||
|
Password=okdsjhasdjhksdj |
||||
|
balance=610 |
||||
|
|
||||
|
7765335=123 |
||||
|
ID=7765335 |
||||
|
Forename=Friedrich |
||||
|
Surname=Moller |
||||
|
Password=123 |
||||
|
balance=858.2 |
||||
|
|
@ -0,0 +1,2 @@ |
|||||
|
#define MAX_LENGTH 200 |
||||
|
#define CUSTOMER_DATA_FILE "src/CustomerData.txt" |
@ -0,0 +1,12 @@ |
|||||
|
#include "calculatorAdd.h" |
||||
|
|
||||
|
|
||||
|
// Note: |
||||
|
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
||||
|
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
||||
|
|
||||
|
float calculatorAdd(float num1,float num2) |
||||
|
{ |
||||
|
return num1+num2; |
||||
|
} |
||||
|
|
@ -0,0 +1,3 @@ |
|||||
|
#include<stdio.h> |
||||
|
#include<stdlib.h> |
||||
|
float calculatorAdd(float num1,float num2); |
@ -0,0 +1,11 @@ |
|||||
|
#include "calculatorDivide.h" |
||||
|
// Note: |
||||
|
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
||||
|
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
||||
|
|
||||
|
|
||||
|
float calculatorDivide(float num1, float num2) |
||||
|
{ |
||||
|
return num1 / num2; |
||||
|
} |
||||
|
|
@ -0,0 +1,3 @@ |
|||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
float calculatorDivide(float num1, float num2); |
@ -0,0 +1,18 @@ |
|||||
|
#include "calculatorFactorial.h" |
||||
|
// Note: |
||||
|
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
||||
|
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
||||
|
|
||||
|
|
||||
|
int calculatorFactorial(int num) //implement recursion. The function calls itself so many times, till the breaking condition is fulfilled. |
||||
|
{ |
||||
|
if (num == 0) //breaking condition |
||||
|
{ |
||||
|
return 1; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
return num * calculatorFactorial(num - 1); //If its not breaking condition, then multiply the number with the same function implemented on the previous number. Eventually it will reach breaking condition. |
||||
|
} |
||||
|
} |
||||
|
|
@ -0,0 +1,3 @@ |
|||||
|
#include<stdio.h> |
||||
|
#include<stdlib.h> |
||||
|
int calculatorFactorial(int num); |
@ -0,0 +1,26 @@ |
|||||
|
#include "calculatorGetUserInput.h" |
||||
|
// Note: |
||||
|
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
||||
|
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
||||
|
|
||||
|
int allowOnly() //int allowOnly() is helpful for indirectly testing void calculatorGetUserInput(). |
||||
|
{ |
||||
|
const int a = 1; |
||||
|
if(a == 1) //Just a random constant which has a role in testing |
||||
|
{ |
||||
|
return 1; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void calculatorGetUserInput(float *num1, float *num2) |
||||
|
{ |
||||
|
if (allowOnly() == 1) //only if int allowOnly() returns 1, void calculatorGetUserInput will display the desired output. |
||||
|
{ |
||||
|
printf("number1: "); |
||||
|
scanf("%f", num1); |
||||
|
printf("number2: "); |
||||
|
scanf("%f", num2); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
@ -0,0 +1,5 @@ |
|||||
|
#include<stdio.h> |
||||
|
#include<stdlib.h> |
||||
|
void calculatorGetUserInput(float *num1, float *num2); |
||||
|
int allowOnly(); |
||||
|
//const int a = 1; //Just a random constant which has a role in testing |
@ -0,0 +1,22 @@ |
|||||
|
#include "calculatorGetUserInputFactorial.h" |
||||
|
// Note: |
||||
|
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
||||
|
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
||||
|
|
||||
|
int allowWhen()// int allowWhen() is helpful for indirectly unittesting void calculatorGetUserInputFactorial() |
||||
|
{ |
||||
|
//ufc is unitTestConstant, which has a role in unittesting void calculatorGetUserInputFactorial() |
||||
|
const int utc = 1; |
||||
|
if(utc == 1) |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
void calculatorGetUserInputFactorial(int *num) |
||||
|
{ |
||||
|
if(allowWhen() == 1)//Only when int allowWhen() returns 1, void calculatorGetUserInputFactorial() will display desired Output |
||||
|
{ |
||||
|
printf("num: "); |
||||
|
scanf("%d", num); |
||||
|
} |
||||
|
} |
||||
|
|
@ -0,0 +1,4 @@ |
|||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
int allowWhen(); |
||||
|
void calculatorGetUserInputFactorial(int *num); |
@ -0,0 +1,10 @@ |
|||||
|
#include "calculatorMultiply.h" |
||||
|
// Note: |
||||
|
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
||||
|
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
||||
|
|
||||
|
float calculatorMultiply(float num1, float num2) |
||||
|
{ |
||||
|
return num1 * num2; |
||||
|
} |
||||
|
|
@ -0,0 +1,3 @@ |
|||||
|
#include<stdio.h> |
||||
|
#include<stdlib.h> |
||||
|
float calculatorMultiply(float num1, float num2); |
@ -0,0 +1,12 @@ |
|||||
|
#include "calculatorSubtract.h" |
||||
|
|
||||
|
// Note: |
||||
|
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
||||
|
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
||||
|
|
||||
|
float calculatorSubtract (float num1, float num2) |
||||
|
{ |
||||
|
return num1 - num2; |
||||
|
} |
||||
|
|
||||
|
|
@ -0,0 +1,4 @@ |
|||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
|
||||
|
float calculatorSubtract(float num1, float num2); |
@ -0,0 +1,30 @@ |
|||||
|
#include "checkLoanEligibility.h" |
||||
|
#include "_file_information.h" |
||||
|
|
||||
|
bool checkLoanEligibility(int user_id) { |
||||
|
|
||||
|
// Eligible only when user is present in CustomerDataFile |
||||
|
|
||||
|
bool keep_reading = true; |
||||
|
bool eligibility = false; |
||||
|
char buffer[MAX_LENGTH]; |
||||
|
|
||||
|
FILE *file = fopen(CUSTOMER_DATA_FILE, "r"); |
||||
|
|
||||
|
while(keep_reading) { |
||||
|
fgets(buffer, MAX_LENGTH, file); |
||||
|
|
||||
|
if (feof(file)) { |
||||
|
keep_reading = false; |
||||
|
} |
||||
|
if(user_id == atoi(buffer)) { |
||||
|
eligibility = true; |
||||
|
keep_reading = false; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
fclose(file); |
||||
|
return eligibility; |
||||
|
|
||||
|
} |
@ -0,0 +1,10 @@ |
|||||
|
#ifndef CHECKLOANELIGIBILITY_H_ |
||||
|
#define CHECKLOANELIGIBILITY_H_ |
||||
|
|
||||
|
#include <stdio.h> |
||||
|
#include <stdbool.h> |
||||
|
#include <stdlib.h> |
||||
|
|
||||
|
bool checkLoanEligibility(int user_id); |
||||
|
|
||||
|
#endif |
@ -0,0 +1,129 @@ |
|||||
|
#include "createCustomer.h" |
||||
|
/*Code written by Julius Philipp Engel, fdai7057*/ |
||||
|
int generateID() |
||||
|
{ |
||||
|
srand(clock()); |
||||
|
const int MIN = 1000000, MAX = 9000001; |
||||
|
int pseudoRandomIDForCustomer = (rand() % MAX) + MIN; |
||||
|
return pseudoRandomIDForCustomer; |
||||
|
} |
||||
|
|
||||
|
void collectCustomerProperties() |
||||
|
{ |
||||
|
customer_t instance; |
||||
|
instance.forename = calloc(15+1,sizeof(char)); |
||||
|
instance.surname = calloc(15+1,sizeof(char)); |
||||
|
instance.password = calloc(20+1,sizeof(char)); |
||||
|
instance.ID = generateID(); |
||||
|
int letterCounter = 0; |
||||
|
int letterMaximum = 15; |
||||
|
int errorResult = 0; |
||||
|
char userInput=' '; |
||||
|
bool inputTooLong = false, foundComma = false; |
||||
|
printf("To create a new user, enter the information required below.\n"); |
||||
|
printf("Enter forename (max. 15 letters):\n"); |
||||
|
while(letterCounter<letterMaximum && (userInput=getchar())!='\n'){ |
||||
|
*(instance.forename+letterCounter) = userInput; |
||||
|
++letterCounter; |
||||
|
if(letterCounter>=letterMaximum){ |
||||
|
inputTooLong = true; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
if(inputTooLong){ |
||||
|
errorResult = errorMessage(-7); |
||||
|
if(errorResult==-7) exit(-1); |
||||
|
} |
||||
|
else{ |
||||
|
*(instance.forename+letterCounter) = '\0'; |
||||
|
letterCounter = 0; |
||||
|
} |
||||
|
if(!isLetterOfAlphabet(instance.forename)){ |
||||
|
errorResult = errorMessage(-10); |
||||
|
exit(-1); |
||||
|
} |
||||
|
printf("Enter surname (max. 15 letters):\n"); |
||||
|
while(letterCounter<letterMaximum && (userInput=getchar())!='\n'){ |
||||
|
*(instance.surname+letterCounter) = userInput; |
||||
|
++letterCounter; |
||||
|
if(letterCounter>=letterMaximum){ |
||||
|
inputTooLong = true; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
if(inputTooLong){ |
||||
|
errorResult = errorMessage(-8); |
||||
|
if(errorResult==-8) exit(-1); |
||||
|
}else{ |
||||
|
*(instance.surname+letterCounter) = '\0'; |
||||
|
letterCounter = 0; |
||||
|
} |
||||
|
if(!isLetterOfAlphabet(instance.surname)){ |
||||
|
errorResult = errorMessage(-11); |
||||
|
if(errorResult==-11) exit(-1); |
||||
|
} |
||||
|
printf("Enter password (max. 20 letters):\n"); |
||||
|
letterMaximum = 20; |
||||
|
while(letterCounter<letterMaximum && (userInput=getchar())!='\n'){ |
||||
|
*(instance.password+letterCounter) = userInput; |
||||
|
++letterCounter; |
||||
|
if(letterCounter>=letterMaximum){ |
||||
|
inputTooLong = true; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
if(inputTooLong){ |
||||
|
errorResult=errorMessage(-9); |
||||
|
if(errorResult==-9) exit(-1); |
||||
|
}else{ |
||||
|
*(instance.password+letterCounter) = '\0'; |
||||
|
} |
||||
|
|
||||
|
letterCounter = 0; |
||||
|
printf("Enter balance (max. 10 digits):\n"); |
||||
|
char *balanceCharacters = calloc(10+1+1+1,sizeof(char)); |
||||
|
letterMaximum = 10; |
||||
|
while(letterCounter<=letterMaximum && (userInput=getchar())!='\n'){ |
||||
|
*(balanceCharacters+letterCounter) = userInput; |
||||
|
++letterCounter; |
||||
|
if(letterCounter>letterMaximum){ |
||||
|
inputTooLong = true; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
if(inputTooLong){ |
||||
|
errorResult = errorMessage(-12); |
||||
|
if(errorResult==-12) exit(-1); |
||||
|
}else{ |
||||
|
if(!foundComma){ |
||||
|
*(balanceCharacters+letterCounter) = '.'; |
||||
|
++letterCounter; |
||||
|
*(balanceCharacters+letterCounter) = '0'; |
||||
|
++letterCounter; |
||||
|
} |
||||
|
*(balanceCharacters+letterCounter) = '\0'; |
||||
|
} |
||||
|
if(!everyCharacterIsDigit(balanceCharacters)){ |
||||
|
puts("You have entered a character that is not a number. This is not allowed. Aborting!"); |
||||
|
exit(-1); |
||||
|
} |
||||
|
instance.balance = balanceToDouble(balanceCharacters); |
||||
|
printf("Account successfully created. Your ID is: %d. Note it somewhere!\n",instance.ID); |
||||
|
customer_t *referenceToCustomerInstance = &instance; |
||||
|
writeCustomerPropertiesToFile(referenceToCustomerInstance); |
||||
|
} |
||||
|
|
||||
|
void writeCustomerPropertiesToFile(customer_t *referenceToCustomerInstance) |
||||
|
{ |
||||
|
FILE *customerData = fopen("CustomerData.txt","a"); |
||||
|
int errorResult = 0; |
||||
|
if(customerData!=NULL){ |
||||
|
fprintf(customerData,"%s\nID=%d\nForename=%s\nSurname=%s\nPassword=%s\nBalance=%.4f€\n\n", |
||||
|
generateCheckString(referenceToCustomerInstance->ID, referenceToCustomerInstance->password),referenceToCustomerInstance->ID,referenceToCustomerInstance->forename,referenceToCustomerInstance->surname,referenceToCustomerInstance->password, referenceToCustomerInstance->balance); |
||||
|
fclose(customerData); |
||||
|
} |
||||
|
else{ |
||||
|
errorResult = errorMessage(-6); |
||||
|
if(errorResult==-6) exit(-1); |
||||
|
} |
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
#ifndef CREATE_CUSTOMER_H |
||||
|
#define CREATE_CUSTOMER_H |
||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <stdbool.h> |
||||
|
#include <time.h> |
||||
|
#include "customerProperties.h" |
||||
|
#include "helperFunctions.h" |
||||
|
#include "error.h" |
||||
|
int generateID(); |
||||
|
void collectCustomerProperties(); |
||||
|
void writeCustomerPropertiesToFile(customer_t *); |
||||
|
#endif |
@ -0,0 +1,234 @@ |
|||||
|
|
||||
|
#include "createEmployeeAccount.h" |
||||
|
#include "employeeLogin.h" |
||||
|
|
||||
|
|
||||
|
bool isValidEmployeeID(const char* employeeId,const int maximumStringLength) |
||||
|
{ |
||||
|
int employeeIdLength = strlen(employeeId); |
||||
|
/* looping through the employeeId string until a space is found to return false or true otherwise*/ |
||||
|
for(int i=0;i<employeeIdLength;i++) |
||||
|
{ |
||||
|
if(employeeId[i]==' ') |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
return employeeIdLength <= maximumStringLength ; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
bool isValidPassword( char *password,const int minimumLength) |
||||
|
{ |
||||
|
/*created a pointer(*stringpointer) which helps loop through characters of the string password*/ |
||||
|
char *stringpointer = password; |
||||
|
bool letterFound = false, symbolFound = false, numberFound = false; |
||||
|
|
||||
|
while(*stringpointer!='\0') |
||||
|
{ |
||||
|
if(isalpha(* stringpointer)) |
||||
|
{ |
||||
|
letterFound = true; |
||||
|
} |
||||
|
else if(isdigit(* stringpointer)) |
||||
|
{ |
||||
|
numberFound = true; |
||||
|
} |
||||
|
else if(ispunct(* stringpointer)) |
||||
|
{ |
||||
|
symbolFound = true; |
||||
|
} |
||||
|
if( strlen(password) >= minimumLength && letterFound && numberFound && symbolFound) |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
++stringpointer; |
||||
|
} |
||||
|
|
||||
|
return false; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
bool isValidName(char* name,const int minimalLength) |
||||
|
{ |
||||
|
int nameLength = strlen(name); |
||||
|
if(nameLength < minimalLength) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
for(int i = 0;i<nameLength;i++) |
||||
|
{ |
||||
|
int currentCharacter = name[i]; |
||||
|
if(isdigit(currentCharacter)||ispunct(currentCharacter)||isspace(currentCharacter)) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
bool isValidPhoneNumber(char *phoneNumber) |
||||
|
{ |
||||
|
int numberLength = strlen(phoneNumber); |
||||
|
|
||||
|
/*this function checks if the 3 first characters a german suffix are*/ |
||||
|
if(phoneNumber[0]!='+' || phoneNumber[1]!='4' || phoneNumber[2]!='9' || numberLength != validNumberLength) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
bool isValidAdress(char *street,char* city,int houseNumber,int postalCode) |
||||
|
{ |
||||
|
bool validStreet = true; |
||||
|
bool validHouseNumber = true; |
||||
|
bool validCity = true; |
||||
|
bool validpostalCode = true; |
||||
|
if(strlen(street)>maximalAdressLength || strlen(street)<minimalAdressLength) |
||||
|
{ |
||||
|
validStreet = false; |
||||
|
} |
||||
|
if(strlen(city)>maximalAdressLength || strlen(city)<minimalAdressLength) |
||||
|
{ |
||||
|
validCity = false; |
||||
|
} |
||||
|
if(houseNumber<1 || houseNumber > 999) |
||||
|
{ |
||||
|
validHouseNumber = false; |
||||
|
} |
||||
|
if(postalCode<1000 || postalCode > 99000) |
||||
|
{ |
||||
|
validpostalCode = false; |
||||
|
} |
||||
|
return (validStreet && validCity && validHouseNumber && validpostalCode); |
||||
|
} |
||||
|
|
||||
|
int StringLengthCounter(char* string) |
||||
|
{ |
||||
|
int characterCounter = 0; |
||||
|
int i = 0; |
||||
|
while(string[i] !='\0') |
||||
|
{ |
||||
|
characterCounter++; |
||||
|
++i; |
||||
|
} |
||||
|
string[characterCounter] = '\0'; |
||||
|
return characterCounter; |
||||
|
} |
||||
|
|
||||
|
/*changed the string parameters to constants as an indicator that the function doesnt modify them*/ |
||||
|
|
||||
|
bool storeEmployeeData(const char *name,const char *lastName,const char *adress,const char *phoneNumber) |
||||
|
{ |
||||
|
FILE* employeesDatalist; |
||||
|
employeesDatalist = fopen("src/employeesData.txt","a"); |
||||
|
if(employeesDatalist == NULL) |
||||
|
{ |
||||
|
printf("Error : could not find file"); |
||||
|
fclose(employeesDatalist); |
||||
|
return false; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
fprintf(employeesDatalist,"\n\nName : %s\nLast name : %s\nAdress : %s\nPhone number : %s",name,lastName,adress,phoneNumber); |
||||
|
fclose(employeesDatalist); |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
bool verifyPassword(char* enteredPassword,char* Confirmation) |
||||
|
{ |
||||
|
return !(strcmp(enteredPassword,Confirmation)); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
bool createNewEmployee(char* employeeId, char* employeePassword) |
||||
|
{ |
||||
|
FILE* employeesFile; |
||||
|
employeesFile = fopen("src/employeesCredentialsList.txt","a"); |
||||
|
|
||||
|
if(employeesFile == NULL) |
||||
|
{ |
||||
|
printf("Error: could not find the list of Employees"); |
||||
|
fclose(employeesFile); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
fprintf(employeesFile,"\n%s %s\n",employeeId,employeePassword); |
||||
|
fclose(employeesFile); |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void getNewEmployeeCredentials() |
||||
|
{ |
||||
|
employeedata *data = (employeedata*)malloc(sizeof(employeedata)); |
||||
|
char employeeId[maxLength]; |
||||
|
char employeePassword[maxLength]; |
||||
|
char passwordVerfication[maxLength]; |
||||
|
char street[maximalAdressLength]; |
||||
|
char city[maximalAdressLength]; |
||||
|
int houseNumber; |
||||
|
char houseNumberString[10]; |
||||
|
int postalCode; |
||||
|
char postalCodeString[10]; |
||||
|
|
||||
|
printf("please enter your wished Id :\n"); |
||||
|
/*Added the regular expression [^\n] so that the string keep on getting read until a newline '\n' is found*/ |
||||
|
scanf(" %[^\n]s",employeeId); |
||||
|
employeeId[maxLength] = '\0'; |
||||
|
|
||||
|
printf("\nplease enter your wished Password :\n"); |
||||
|
scanf(" %[^\n]s",employeePassword); |
||||
|
employeePassword[strlen(employeePassword)] = '\0'; |
||||
|
|
||||
|
printf("\nplease confirm your Password :\n"); |
||||
|
scanf(" %[^\n]s",passwordVerfication); |
||||
|
passwordVerfication[strlen(employeePassword)] = '\0'; |
||||
|
|
||||
|
if(verifyPassword(passwordVerfication,employeePassword) && isValidPassword(employeePassword,minPasswordLength) && isValidEmployeeID(employeeId,maxLength)) |
||||
|
{ |
||||
|
printf("\n\nplease enter your first name\n"); |
||||
|
scanf(" %[^\n]s",data->firstName); |
||||
|
|
||||
|
printf("\n\nplease enter your last name\n"); |
||||
|
scanf(" %[^\n]s",data->lastName); |
||||
|
|
||||
|
if(isValidName(data->firstName,minimumNameLength) && isValidName(data->lastName,minimumNameLength)) |
||||
|
{ |
||||
|
printf("\n\nplease enter your adress\n"); |
||||
|
scanf(" %[^\n]s",data->address); |
||||
|
|
||||
|
printf("\n\nplease enter your Phone number\n"); |
||||
|
scanf(" %[^\n]s",data->phoneNumber); |
||||
|
if(isValidPhoneNumber(data->phoneNumber)) |
||||
|
{ |
||||
|
createNewEmployee(employeeId,employeePassword) ? |
||||
|
printf("\n\n Account created successfully !\n\n") : |
||||
|
printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); |
||||
|
storeEmployeeData(data->firstName,data->lastName,data->address,data->phoneNumber); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
printf("\nInvalid phone number!\n"); |
||||
|
} |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
printf("the given name contains unwanted characters(spaces, symbols,numbers)"); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
printf("\nError! one of these conditions is not met in your input.\n"); |
||||
|
printf("\n-The entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol.\n"); |
||||
|
printf("\n-The entered ID should contain a maximum of 20 letters.\n"); |
||||
|
printf("\n-The verification password should match with the entered password.\n"); |
||||
|
} |
||||
|
} |
||||
|
|
@ -0,0 +1,39 @@ |
|||||
|
#ifndef CREATEEMPLOYEEACCOUNT_H_ |
||||
|
#define CREATEEMPLOYEEACCOUNT_H_ |
||||
|
|
||||
|
#include<stdio.h> |
||||
|
#include<stdlib.h> |
||||
|
#include<stdbool.h> |
||||
|
#include<string.h> |
||||
|
#include<ctype.h> |
||||
|
|
||||
|
#define minPasswordLength 5 |
||||
|
#define minimumNameLength 4 |
||||
|
#define maxLength 21 |
||||
|
#define validNumberLength 14 |
||||
|
#define maximalAdressLength 20 |
||||
|
#define minimalAdressLength 3 |
||||
|
|
||||
|
struct employeesInformations |
||||
|
{ |
||||
|
char firstName[15]; |
||||
|
char lastName[15]; |
||||
|
char address[100]; |
||||
|
char phoneNumber[15]; |
||||
|
}; |
||||
|
typedef struct employeesInformations employeedata; |
||||
|
|
||||
|
bool isValidEmployeeID(const char* employee, int maximumLength); |
||||
|
bool isValidPassword( char* password, int minimumLength); |
||||
|
bool isValidName(char* name,int minimalLength); |
||||
|
bool isValidPhoneNumber(char *phoneNumber); |
||||
|
bool isValidAdress(char *street,char* city,int houseNumber,int postalCode); |
||||
|
bool storeEmployeeData(const char *name,const char *lastName,const char *adress,const char *phoneNumber); |
||||
|
bool verifyPassword(char* enteredPassword,char* passwordConfirmation); |
||||
|
bool createNewEmployee(char* employeeId, char* employeePassword); |
||||
|
|
||||
|
int StringLengthCounter(char* string); |
||||
|
|
||||
|
void getNewEmployeeCredentials(); |
||||
|
|
||||
|
#endif |
@ -0,0 +1,20 @@ |
|||||
|
#include "currencyExchange.h" |
||||
|
|
||||
|
float convert(float euro, int newCurrencyCode) { |
||||
|
switch(newCurrencyCode) { |
||||
|
case CURRENCY_CODE_USD: |
||||
|
return ( euro * USD_RATE_OF_ONE_EURO ); |
||||
|
|
||||
|
case CURRENCY_CODE_GBP: |
||||
|
return ( euro * GBP_RATE_OF_ONE_EURO ); |
||||
|
|
||||
|
case CURRENCY_CODE_JAPANESE_YEN: |
||||
|
return ( euro * JAPANESE_YEN_RATE_OF_ONE_EURO ); |
||||
|
|
||||
|
case CURRENCY_CODE_CHINESE_YUAN: |
||||
|
return ( euro * CHINESE_YUAN_RATE_OF_ONE_EURO ); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
return -1; |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
#ifndef CURRENCYEXCHANGE_H_ |
||||
|
#define CURRENCYEXCHANGE_H_ |
||||
|
|
||||
|
#include <stdio.h> |
||||
|
|
||||
|
#define USD_RATE_OF_ONE_EURO 1.07 |
||||
|
#define GBP_RATE_OF_ONE_EURO 0.89 |
||||
|
#define JAPANESE_YEN_RATE_OF_ONE_EURO 140.9 |
||||
|
#define CHINESE_YUAN_RATE_OF_ONE_EURO 7.29 |
||||
|
|
||||
|
#define CURRENCY_CODE_USD 1 |
||||
|
#define CURRENCY_CODE_GBP 2 |
||||
|
#define CURRENCY_CODE_JAPANESE_YEN 3 |
||||
|
#define CURRENCY_CODE_CHINESE_YUAN 4 |
||||
|
|
||||
|
float convert(float euro, int newCurrencyCode); |
||||
|
|
||||
|
#endif |
@ -0,0 +1,65 @@ |
|||||
|
#include "currentCustomerAccountBalance.h" |
||||
|
//#include "_file_information.h" |
||||
|
|
||||
|
|
||||
|
float fetchBalanceFromBalanceString(char balance_String[MAX_LENGTH]) { |
||||
|
float balance = 0; |
||||
|
char *token = strtok(balance_String, "="); // separates string to two parts |
||||
|
while (token != NULL) { |
||||
|
if (atoi(token) != 0) { |
||||
|
balance = atof(token); // converts string to float |
||||
|
break; |
||||
|
} |
||||
|
token = strtok(NULL, "="); |
||||
|
} |
||||
|
return balance; |
||||
|
} |
||||
|
|
||||
|
float readFileAndGetAvailableBalance(FILE *file, char stringID[MAX_LENGTH]) { |
||||
|
float balance = 0; |
||||
|
bool keep_reading = true; |
||||
|
char buffer[MAX_LENGTH]; |
||||
|
char balance_String[MAX_LENGTH]; |
||||
|
|
||||
|
while(keep_reading) { |
||||
|
fgets(buffer, MAX_LENGTH, file); |
||||
|
if (feof(file)) { |
||||
|
keep_reading = false; |
||||
|
} |
||||
|
else if(strstr(buffer, stringID)) { |
||||
|
for (int i = 0; i < 4; i++) { |
||||
|
fgets(buffer, MAX_LENGTH, file); |
||||
|
} |
||||
|
strcpy(balance_String, buffer); |
||||
|
balance = fetchBalanceFromBalanceString(balance_String); |
||||
|
keep_reading = false; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
return balance; |
||||
|
} |
||||
|
|
||||
|
float getAvailableAccountBalance(int user_id) { |
||||
|
float availableBalance = 0; |
||||
|
char stringID[MAX_LENGTH] = "ID="; |
||||
|
char user_id_as_string[MAX_LENGTH]; |
||||
|
|
||||
|
sprintf(user_id_as_string, "%d", user_id); // converts user_id to string |
||||
|
strcat(stringID, user_id_as_string); |
||||
|
// Now stringID is "ID=user_id" |
||||
|
|
||||
|
FILE *file = fopen(CUSTOMER_DATA_FILE, "r"); |
||||
|
if(file == 0) { |
||||
|
printf("Error: customer data file cannot be opened!\n"); |
||||
|
return 0; |
||||
|
} |
||||
|
else { |
||||
|
availableBalance = readFileAndGetAvailableBalance(file, stringID); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
fclose(file); |
||||
|
|
||||
|
return availableBalance; |
||||
|
|
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
#ifndef CurrentCustomerAccountBalance_H |
||||
|
#define CurrentCustomerAccountBalance_H |
||||
|
|
||||
|
|
||||
|
#include <stdio.h> |
||||
|
#include <stdbool.h> |
||||
|
#include <string.h> |
||||
|
#include <stdlib.h> |
||||
|
|
||||
|
#include "_file_information.h" |
||||
|
|
||||
|
float getAvailableAccountBalance(int user_id); |
||||
|
float fetchBalanceFromBalanceString(char balance_String[MAX_LENGTH]); |
||||
|
float readFileAndGetAvailableBalance(FILE *file, char stringID[MAX_LENGTH]); |
||||
|
|
||||
|
#endif |
@ -0,0 +1,78 @@ |
|||||
|
#include "customerMenu.h" |
||||
|
#include "sendMoney.h" |
||||
|
#include "withdrawMoney.h" |
||||
|
#include "depositMoney.h" |
||||
|
|
||||
|
|
||||
|
int customerChoiceForMenuItem(int numberOfMenuItem, unsigned int *ptr) |
||||
|
{ |
||||
|
int returnStatus = 0; |
||||
|
int ID = *ptr; |
||||
|
switch(numberOfMenuItem){ |
||||
|
case 1: |
||||
|
puts("You have chosen to send money.\n"); |
||||
|
returnStatus = 1; |
||||
|
sendMoney(ID); |
||||
|
break; |
||||
|
case 2: |
||||
|
puts("You have chosen to withdraw money.\n"); |
||||
|
returnStatus = 2; |
||||
|
withdraw(ID); |
||||
|
break; |
||||
|
case 3: |
||||
|
puts("You have chosen to deposit money.\n"); |
||||
|
returnStatus = 3; |
||||
|
depositMoney(ID); |
||||
|
break; |
||||
|
case 4: |
||||
|
puts("You have chosen to request a loan.\n"); |
||||
|
returnStatus = 4; |
||||
|
requestLoan(); |
||||
|
break; |
||||
|
default: |
||||
|
puts("Invalid input."); |
||||
|
returnStatus = -1; |
||||
|
} |
||||
|
return returnStatus; |
||||
|
} |
||||
|
|
||||
|
void showAllMenuEntries(unsigned int *ptr) |
||||
|
{ |
||||
|
|
||||
|
int userDecision = 0; |
||||
|
|
||||
|
puts("\n\n"); |
||||
|
puts("CUSTOMER MENU"); |
||||
|
|
||||
|
puts("\n"); |
||||
|
puts("Select between (1-4):"); |
||||
|
puts("\n\n\n"); |
||||
|
|
||||
|
puts("->->->1. send money<-<-<-"); |
||||
|
puts("\n\n\n"); |
||||
|
|
||||
|
puts("->->->2. withdraw money<-<-<-"); |
||||
|
puts("\n\n\n"); |
||||
|
|
||||
|
puts("->->->3. deposit money<-<-<-"); |
||||
|
puts("\n\n\n"); |
||||
|
|
||||
|
puts("->->->4. request loan<-<-<-"); |
||||
|
puts("\n\n\n"); |
||||
|
|
||||
|
puts("Your decision: "); |
||||
|
scanf("%d",&userDecision); |
||||
|
customerChoiceForMenuItem(userDecision, ptr); |
||||
|
} |
||||
|
|
||||
|
void menu(unsigned int *ptr) |
||||
|
{ |
||||
|
if(ptr==NULL){ |
||||
|
puts("Invalid pointer. Aborting!"); |
||||
|
exit(-1); |
||||
|
}else{ |
||||
|
puts("Welcome!"); |
||||
|
printf("Your ID is: %u\n", *ptr); |
||||
|
showAllMenuEntries(ptr); |
||||
|
} |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
#include "customerProperties.h" |
||||
|
#include "requestLoan.h" |
||||
|
int customerChoiceForMenuItem(int, unsigned int *pointer); |
||||
|
void showAllMenuEntries(unsigned int *pointer); |
||||
|
void menu(unsigned int *pointer); |
@ -0,0 +1,11 @@ |
|||||
|
#ifndef CUSTOMER_PROPERTIES_H |
||||
|
#define CUSTOMER_PROPERTIES_H |
||||
|
typedef struct Customer |
||||
|
{ |
||||
|
unsigned int ID; |
||||
|
char *IDAsString; |
||||
|
char *password; |
||||
|
char *forename, *surname; |
||||
|
double balance; |
||||
|
}customer_t; |
||||
|
#endif |
@ -0,0 +1,71 @@ |
|||||
|
#include "depositMoney.h" |
||||
|
#include "updateCustomerAccountBalance.h" |
||||
|
#include "currentCustomerAccountBalance.h" |
||||
|
|
||||
|
void askToTryAgain(bool afterError, int customerID){ |
||||
|
printf("\n"); |
||||
|
char choice; |
||||
|
printf("%s [y] yes [n] no: ", afterError ? "Would you like to try again?" : "Would you like to make another deposit?"); |
||||
|
scanf(" %c", &choice); |
||||
|
if (choice == 'y') { |
||||
|
depositMoney(customerID); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
bool depositMoney(int customerID){ |
||||
|
float availableAccountBalance = getAvailableAccountBalance(customerID); |
||||
|
if (availableAccountBalance < 0) { |
||||
|
printf("\nCould not retrieve account balance. Please contact staff.\n"); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
printf("\nPlease enter the amount you want to deposit: "); |
||||
|
float amountToDeposit = 0; |
||||
|
scanf("%f", &amountToDeposit); |
||||
|
|
||||
|
if (amountToDeposit < 0) { |
||||
|
printf("\nInvalid input."); |
||||
|
askToTryAgain(true, customerID); |
||||
|
return false; |
||||
|
} |
||||
|
else if (amountToDeposit < MINIMUM_DEPOSIT_AMOUNT) { |
||||
|
printf("\nThe amount you entered is lower than the minimum amount."); |
||||
|
askToTryAgain(true, customerID); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
if (updateAvailableAccountBalance(customerID, availableAccountBalance + amountToDeposit)) { |
||||
|
printf("\nYou have successfully deposited %.2f. New account balance is %.2f", amountToDeposit, availableAccountBalance + amountToDeposit); |
||||
|
askToTryAgain(false, customerID); |
||||
|
return true; |
||||
|
} |
||||
|
else { |
||||
|
printf("\nSomething went wrong. Please contact staff."); |
||||
|
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(){ |
||||
|
depositSpecificAmount(1234,5000); |
||||
|
//depositMoney(1234); |
||||
|
return 0; |
||||
|
} |
||||
|
*/ |
@ -0,0 +1,9 @@ |
|||||
|
#include <stdio.h> |
||||
|
#include "customerProperties.h" |
||||
|
#include <stdbool.h> |
||||
|
#define MINIMUM_DEPOSIT_AMOUNT 5 |
||||
|
|
||||
|
|
||||
|
bool depositMoney(int customerID); |
||||
|
void askToTryAgain(bool afterError, int customerID); |
||||
|
bool depositSpecificAmount(int customerID, float amount); |
@ -0,0 +1,20 @@ |
|||||
|
#include "displayDisclaimer.h" |
||||
|
|
||||
|
void displayDisclaimer(){ |
||||
|
printf(" W E L C O M E T O \n"); |
||||
|
printf(" .______ .___ ___. _______.\n"); |
||||
|
printf(" | _ \\ | \\/ | / |\n"); |
||||
|
printf(" | |_) | | \\ / | | (----`\n"); |
||||
|
printf(" | _ < | |\\/| | \\ \\ \n"); |
||||
|
printf(" | |_) | | | | | .----) | \n"); |
||||
|
printf(" |______/ |__| |__| |_______/ \n"); |
||||
|
printf(" \n"); |
||||
|
printf("B A N K M A N A G E M E N T S Y S T E M\n"); |
||||
|
printf(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:\n"); |
||||
|
printf("Created by Atharva, Can, Haytham, Julius, Shivam, and Yahya for AI1001.\n"); |
||||
|
} |
||||
|
|
||||
|
// int main(){ |
||||
|
// displayDisclaimer(); |
||||
|
// return 1; |
||||
|
// } |
@ -0,0 +1,7 @@ |
|||||
|
#ifndef DISPLAYDISCLAIMER_H_ |
||||
|
#define DISPLAYDISCLAIMER_H_ |
||||
|
#include <stdio.h> |
||||
|
|
||||
|
void displayDisclaimer(); |
||||
|
|
||||
|
#endif |
@ -0,0 +1,88 @@ |
|||||
|
#include "displayMenuCalculator.h" |
||||
|
#include "calculatorGetUserInput.h" |
||||
|
#include "calculatorGetUserInputFactorial.h" |
||||
|
#include "calculatorAdd.h" |
||||
|
#include "calculatorSubtract.h" |
||||
|
#include "calculatorMultiply.h" |
||||
|
#include "calculatorDivide.h" |
||||
|
#include "calculatorFactorial.h" |
||||
|
// Note: |
||||
|
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
||||
|
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
||||
|
|
||||
|
int operation1 = 1; |
||||
|
int operation2 = 2; |
||||
|
int operation3 = 3; |
||||
|
int operation4 = 4; |
||||
|
int operation5 = 5; |
||||
|
|
||||
|
int check() |
||||
|
{ |
||||
|
const int rConst = 1; // RandomConstant created for indirectly testing void displayMenuCalculator() |
||||
|
if(rConst == 1)// RandomConstant created for indirectly testing void displayMenuCalculator() |
||||
|
{ |
||||
|
return 1; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void displayMenuCalculator(char x) //Displays the correct output, only when x is c. |
||||
|
{ |
||||
|
float num1, num2, answer; //Created for storing numbers for addition, subtraction, multiplication and division and the final answer. |
||||
|
int num; //Created specially for calculatorFactorial() |
||||
|
int choose; |
||||
|
|
||||
|
if(x == 'c') //calculator can be activated by adding 'c' in void displayMenuCalculator() |
||||
|
{ |
||||
|
if(check() == 1) |
||||
|
{ //The Main Menu of the calculator |
||||
|
printf(" %d. Add\n", operation1); |
||||
|
printf(" %d. Subtract\n", operation2); |
||||
|
printf(" %d. Multiply\n", operation3); |
||||
|
printf(" %d. Divide\n", operation4); |
||||
|
printf(" %d. Factorial\n", operation5); |
||||
|
|
||||
|
printf("Enter your choice: "); // Takes the choice of operations from the user |
||||
|
scanf("%d", &choose); // Saves the choice |
||||
|
|
||||
|
switch (choose) |
||||
|
{ //takes user's choice and calls operation-functions accordingly |
||||
|
case 1: |
||||
|
calculatorGetUserInput(&num1, &num2); |
||||
|
answer = calculatorAdd(num1, num2); |
||||
|
printf("Answer: %f\n", answer); |
||||
|
break; |
||||
|
|
||||
|
case 2: |
||||
|
calculatorGetUserInput(&num1, &num2); |
||||
|
answer = calculatorSubtract(num1, num2); |
||||
|
printf("Answer: %f\n", answer); |
||||
|
break; |
||||
|
|
||||
|
case 3: |
||||
|
calculatorGetUserInput(&num1, &num2); |
||||
|
answer = calculatorMultiply(num1, num2); |
||||
|
printf("Answer: %f\n", answer); |
||||
|
break; |
||||
|
|
||||
|
case 4: |
||||
|
calculatorGetUserInput(&num1, &num2); |
||||
|
answer = calculatorDivide(num1, num2); |
||||
|
printf("Answer: %f\n", answer); |
||||
|
break; |
||||
|
|
||||
|
case 5: |
||||
|
calculatorGetUserInputFactorial(&num); //Created specially for factorial which gets a number from user. |
||||
|
answer = calculatorFactorial(num); |
||||
|
printf("Answer: %f\n", answer); |
||||
|
break; |
||||
|
|
||||
|
default: |
||||
|
printf("Invalid choice\n"); |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
@ -0,0 +1,4 @@ |
|||||
|
#include<stdio.h> |
||||
|
#include<stdlib.h> |
||||
|
int check(); //int check() is helpful for indirectly testing void displayMenuCalculator() |
||||
|
void displayMenuCalculator(char x); //Displays the correct output, only when x is c. |
@ -0,0 +1,14 @@ |
|||||
|
char *stringConcatenation(char string_1*, char string_2*): |
||||
|
|
||||
|
This function takes two char pointers. In this function a new string is created. This new string is the concatenation of string_1 and string_2. The size of the new string is the length of string_1 plus the length of string_2 plus one for '\0'. This function is needed when creating an unique check string for a customer. |
||||
|
|
||||
|
char *to_string(int number): |
||||
|
|
||||
|
This function takes an integer variable as its argument. It returns an string that contains the digits of number. For example to_string(176) would return "176\0". This function is needed to write data in form of characters into the customer file. |
||||
|
|
||||
|
|
||||
|
char *generateCheckString(int customerID, char *password): |
||||
|
|
||||
|
The purpose of this function is to generate a string that is needed when a user wants to login. This string is searched for in the customer-data file and if it is found, the login is successful. This function is needed when a new user is created because then it is written in the file for the first time. |
||||
|
The format of the returned string is [ID]=[PASSWORD]. |
||||
|
For example generateCheckString(177,"tree") would return "177=tree\0". |
@ -0,0 +1,139 @@ |
|||||
|
#include "mainMenu.h" |
||||
|
#include "employeeLogin.h" |
||||
|
#include "showGeneralInfoEmployee.h" |
||||
|
|
||||
|
|
||||
|
bool employeesAccess(char* employeesAccessCode) |
||||
|
{ |
||||
|
|
||||
|
return !(strcmp(employeesAccessCode,employeeAccessKey)); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
int checkEmployeeCredentials(char *inputUsername, char *inputPassword) |
||||
|
{ |
||||
|
|
||||
|
char* listUsername = malloc(credentialLength * sizeof(char*)); |
||||
|
char* listPassword = malloc(credentialLength * sizeof(char*)); |
||||
|
|
||||
|
FILE* employeeList = fopen("src/employeesCredentialsList.txt","r"); |
||||
|
|
||||
|
if(employeeList == NULL ) |
||||
|
{ |
||||
|
printf("file does not exist"); |
||||
|
exit(1); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
/*loop that checks if the two strings seperated by space exist in the employee list*/ |
||||
|
|
||||
|
while (fscanf(employeeList, "%s %s", listUsername, listPassword) != EOF) |
||||
|
{ |
||||
|
|
||||
|
if (!(strcmp(inputUsername, listUsername)) && !(strcmp(inputPassword, listPassword))) |
||||
|
{ |
||||
|
fclose(employeeList); |
||||
|
return 1; |
||||
|
} |
||||
|
else if(!(strcmp(inputUsername, listUsername)) && strcmp(inputPassword, listPassword)) |
||||
|
{ |
||||
|
fclose(employeeList); |
||||
|
return 2; |
||||
|
} |
||||
|
} |
||||
|
fclose(employeeList); |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
free(inputUsername); |
||||
|
free(inputPassword); |
||||
|
} |
||||
|
|
||||
|
void getEmployeeAccessCode() |
||||
|
{ |
||||
|
char accessCode[10]; |
||||
|
|
||||
|
int remainingAttempts = 10; |
||||
|
|
||||
|
printf("\n\nPlease enter the Access key : "); |
||||
|
|
||||
|
while(remainingAttempts > 0) |
||||
|
{ |
||||
|
scanf("%s",accessCode); |
||||
|
|
||||
|
|
||||
|
if(employeesAccess(accessCode)) |
||||
|
{ |
||||
|
printf("\n\nAccess granted!\n\n"); |
||||
|
|
||||
|
loginAsEmployee(); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
else if(!(employeesAccess(accessCode))) |
||||
|
{ |
||||
|
printf("\n\nAccess key didnt match! try again !\n\n"); |
||||
|
--remainingAttempts; |
||||
|
} |
||||
|
|
||||
|
if(remainingAttempts == 0) |
||||
|
{ |
||||
|
printf("you've reached the maximum number of tries!\nplease contact an employee of a high clearance(2 or higher) \n\n"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void getEmployeeCredentials(char* inputUsername,char* inputPassword) |
||||
|
{ |
||||
|
printf("Enter username: "); |
||||
|
scanf("%s", inputUsername); |
||||
|
|
||||
|
printf("Enter password: "); |
||||
|
scanf("%s", inputPassword); |
||||
|
} |
||||
|
|
||||
|
void loginAsEmployee() |
||||
|
{ |
||||
|
int counter=3; |
||||
|
char* username = malloc(credentialLength * sizeof(char*)); |
||||
|
char* password = malloc(credentialLength * sizeof(char*)); |
||||
|
|
||||
|
while(counter>0) |
||||
|
{ |
||||
|
getEmployeeCredentials(username, password); |
||||
|
|
||||
|
int checkCredentials = checkEmployeeCredentials(username,password); |
||||
|
|
||||
|
|
||||
|
if(checkCredentials == 0) |
||||
|
{ |
||||
|
printf("\n\nUser not found\n\n"); |
||||
|
} |
||||
|
else if(checkCredentials == 2) |
||||
|
{ |
||||
|
printf("\n\nWrong Informations !\nyou have %d tries left\n\n",counter-1); |
||||
|
--counter; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
printf("\n\nUser Approved\n\n"); |
||||
|
showGeneralInfoEmployee(username, password); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if(counter==0) |
||||
|
{ |
||||
|
|
||||
|
printf("you used up all of the tries! account locked\nPlease contact an employee of higher clearance !\n\n"); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
free(username); |
||||
|
free(password); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
@ -0,0 +1,19 @@ |
|||||
|
#ifndef EMPLOYEELOGIN_H_ |
||||
|
#define EMPLOYEELOGIN_H_ |
||||
|
|
||||
|
#define employeeAccessKey "DF9E9A8B5E" |
||||
|
#define credentialLength 20 |
||||
|
|
||||
|
#include<stdbool.h> |
||||
|
|
||||
|
bool employeesAccess(char* employeesAccessCode); |
||||
|
int checkEmployeeCredentials(char* username , char* password); |
||||
|
|
||||
|
void getEmployeeAccessCode(); |
||||
|
void getEmployeeCredentials(char* username, char* password); |
||||
|
void loginAsEmployee(); |
||||
|
|
||||
|
|
||||
|
#endif |
||||
|
|
||||
|
|
@ -0,0 +1,20 @@ |
|||||
|
Atharva Atharvafdai7514 |
||||
|
|
||||
|
Can BlooMaskfdlt3817 |
||||
|
|
||||
|
Haytham TimoDLfdai7207 |
||||
|
|
||||
|
Julius Insertcatfdai7057 |
||||
|
|
||||
|
Mohamed MDfdai6618 |
||||
|
|
||||
|
Shivam Schivam007fdlt3781 |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
@ -0,0 +1,52 @@ |
|||||
|
Name : Atharva |
||||
|
Last name : Naik |
||||
|
Adress : Fulda,leipzigerstrasse,1 |
||||
|
Phone number : +4964169865172 |
||||
|
|
||||
|
|
||||
|
Name : Can |
||||
|
Last name : Hacioglu |
||||
|
Adress : Fulda,leipzigerstrasse,2 |
||||
|
Phone number : +4915973325487 |
||||
|
|
||||
|
|
||||
|
Name : Haytham |
||||
|
Last name : Daoula |
||||
|
Adress : Fulda,leipzigerstrasse,3 |
||||
|
Phone number : +4995435870169 |
||||
|
|
||||
|
|
||||
|
Name : Julius |
||||
|
Last name : Engel |
||||
|
Adress : Fulda,leipzigerstrasse,4 |
||||
|
Phone number : +4939172972187 |
||||
|
|
||||
|
|
||||
|
Name : Mohamed |
||||
|
Last name : Dahi |
||||
|
Adress : Fulda,leipzigerstrasse,5 |
||||
|
Phone number : +4921865106647 |
||||
|
|
||||
|
|
||||
|
Name : Shivam |
||||
|
Last name : Chaudhary |
||||
|
Adress : Fulda,leipzigerstrasse,6 |
||||
|
Phone number : +4918756871384 |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
@ -0,0 +1,59 @@ |
|||||
|
#include "error.h" |
||||
|
|
||||
|
int errorMessage(int errorCode) |
||||
|
{ |
||||
|
int returnValue=0; |
||||
|
switch(errorCode){ |
||||
|
case -1: |
||||
|
// puts("Login not successful."); |
||||
|
returnValue = -1; |
||||
|
break; |
||||
|
case -2: |
||||
|
// puts("Maximum number of attempts reached."); |
||||
|
returnValue = -2; |
||||
|
break; |
||||
|
case -3: |
||||
|
// puts("No menu entry available for this number."); |
||||
|
returnValue = -3; |
||||
|
break; |
||||
|
case -4: |
||||
|
// puts("CustomerData.* not found. Make sure that you've created an user account before logging in for the first time. Without users there is no file. Aborting!"); |
||||
|
returnValue = -4; |
||||
|
break; |
||||
|
case -5: |
||||
|
// puts("You should be at least 18 years old to create a bank account!"); |
||||
|
returnValue = -5; |
||||
|
break; |
||||
|
case -6: |
||||
|
// puts("Error when trying to open a file to create a customer account."); |
||||
|
returnValue = -6; |
||||
|
break; |
||||
|
case -7: |
||||
|
// puts("Forename too long. (length > 15 characters) Aborting!"); |
||||
|
returnValue = -7; |
||||
|
break; |
||||
|
case -8: |
||||
|
// puts("Surname too long. (length > 15 characters) Aborting!"); |
||||
|
returnValue = -8; |
||||
|
break; |
||||
|
case -9: |
||||
|
// puts("Password too long. (length > 20 characters) Aboring!"); |
||||
|
returnValue = -9; |
||||
|
break; |
||||
|
case -10: |
||||
|
// puts("You have entered an invalid character [ä,ö,ü, special characters] for your forename. This is not allowed. Aborting!"); |
||||
|
returnValue = -10; |
||||
|
break; |
||||
|
case -11: |
||||
|
// puts("You have entered an invalid character [ä,ö,ü, special characters] for your surname. This is not allowed. Aborting!"); |
||||
|
returnValue = -11; |
||||
|
break; |
||||
|
case -12: |
||||
|
// puts("You entered too many digits."); |
||||
|
returnValue = -12; |
||||
|
break; |
||||
|
default: |
||||
|
return returnValue; |
||||
|
} |
||||
|
return returnValue; |
||||
|
} |
@ -0,0 +1,3 @@ |
|||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
int errorMessage(int); |
@ -0,0 +1,151 @@ |
|||||
|
#include "helperFunctions.h" |
||||
|
/*Code written by Julius Philipp Engel, fdai7057*/ |
||||
|
|
||||
|
char *stringConcatenation(char *string_1, char *string_2) |
||||
|
{ |
||||
|
int lengthStringOne = strlen(string_1); |
||||
|
int lengthStringTwo = strlen(string_2); |
||||
|
|
||||
|
if(lengthStringOne==0||lengthStringTwo==0){ |
||||
|
printf("Empty strings are not allowed. Aborting.\n"); |
||||
|
exit(-1); |
||||
|
//call error(); |
||||
|
} |
||||
|
|
||||
|
const int totalLength = lengthStringOne + lengthStringTwo + 1; |
||||
|
char *result = calloc(totalLength, sizeof(char)); |
||||
|
int i,j; |
||||
|
for(i=0,j=0;i<totalLength;++i){ |
||||
|
if(i<lengthStringOne){ |
||||
|
*(result+i) = *(string_1+i); |
||||
|
}else{ |
||||
|
*(result+i) = *(string_2+j); |
||||
|
++j; |
||||
|
} |
||||
|
} |
||||
|
*(result+i) = '\0'; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
char *to_string(int number) |
||||
|
{ |
||||
|
if(number==0) |
||||
|
{ |
||||
|
char *str = calloc(2,sizeof(char)); |
||||
|
*(str) = '0'; |
||||
|
*(str+1) = '\0'; |
||||
|
return str; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
int cpy = number, len = 0; |
||||
|
while(number>0){ |
||||
|
++len; |
||||
|
number /= 10; |
||||
|
} |
||||
|
char *str = calloc(len+1, sizeof(char)); |
||||
|
for(int i=0,j=len-1;i<len;++i,--j){ |
||||
|
*(str+j) = '0' + (cpy % 10); |
||||
|
cpy /= 10; |
||||
|
} |
||||
|
*(str+len) = '\0'; |
||||
|
return str; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
unsigned int power(unsigned int base, unsigned int exponent){ |
||||
|
if(base==0&&exponent==0) return 0; |
||||
|
else if(base>=1&&exponent==0) return 1; |
||||
|
else{ |
||||
|
unsigned int result = 1, counter = 0; |
||||
|
while(counter<exponent){ |
||||
|
result *= base; |
||||
|
++counter; |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
bool everyCharacterIsDigit(char *string) |
||||
|
{ |
||||
|
bool onlyDigits = true; |
||||
|
for(int i=0;*(string+i)!='\0';++i){ |
||||
|
if( !(*(string+i)>='0'&&*(string+i)<='9') && *(string+i)!='.'){ |
||||
|
onlyDigits = false; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
return onlyDigits; |
||||
|
} |
||||
|
|
||||
|
bool isLetterOfAlphabet(char *string){ |
||||
|
bool everyCharIsInAlphabet = true; |
||||
|
for(int i=0;*(string+i)!='\0';++i){ |
||||
|
if(!(*(string+i)>='A'&&*(string+i)<='Z') && !(*(string+i)>='a'&&*(string+i)<='z')){ |
||||
|
everyCharIsInAlphabet = false; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
return everyCharIsInAlphabet; |
||||
|
} |
||||
|
|
||||
|
unsigned int toUnsignedInteger(char *ID) |
||||
|
{ |
||||
|
if(everyCharacterIsDigit(ID)){ |
||||
|
unsigned int result = 0; |
||||
|
int IDLength = strlen(ID); |
||||
|
for(int i=0, j = IDLength - 1;i<IDLength;++i,--j){ |
||||
|
result += (*(ID+j) - '0') * power(10,i); |
||||
|
} |
||||
|
return result; |
||||
|
} else { |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
char *generateCheckString(unsigned int customerID, char *customerPassword) |
||||
|
{ |
||||
|
char *IDString = to_string(customerID); |
||||
|
int IDLength = strlen(IDString); |
||||
|
int passwordLength = strlen(customerPassword); |
||||
|
int checkStringLength = IDLength + 1 + passwordLength + 1; |
||||
|
char *checkString = calloc(checkStringLength, sizeof(char)); |
||||
|
checkString = strcat(IDString, "="); |
||||
|
checkString = strcat(checkString, customerPassword); |
||||
|
*(checkString+checkStringLength) = '\0'; |
||||
|
return checkString; |
||||
|
} |
||||
|
|
||||
|
double balanceToDouble(char *balanceAsString) |
||||
|
{ |
||||
|
double result, power; |
||||
|
int i=0, sign; |
||||
|
sign = (*(balanceAsString) == '-') ? -1 : 1; |
||||
|
if(*(balanceAsString)=='+'||*(balanceAsString)=='-'){ |
||||
|
++i; |
||||
|
} |
||||
|
for(result = 0.0; *(balanceAsString+i)!='.';++i){ |
||||
|
result = 10.0 * result + (*(balanceAsString+i) - '0'); |
||||
|
} |
||||
|
if(*(balanceAsString+i)=='.'){ |
||||
|
++i; |
||||
|
} |
||||
|
for(power = 1.0;*(balanceAsString+i)!='\0';++i){ |
||||
|
result = 10.0 * result + (*(balanceAsString+i)- '0'); |
||||
|
power *= 10.0; |
||||
|
} |
||||
|
return sign * result / power; |
||||
|
} |
||||
|
|
||||
|
unsigned int calculateStringLength(char *string){ |
||||
|
int length = 0; |
||||
|
while(*(string+length)!='\0') ++length; |
||||
|
return length; |
||||
|
} |
||||
|
|
||||
|
bool characterIsUpperCase(char inputCharacter) |
||||
|
{ |
||||
|
bool result = (inputCharacter>='A'&&inputCharacter<='Z') ? true : false; |
||||
|
return result; |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
#ifndef STRING_MANIPULATION_H |
||||
|
#define STRING_MANIPULATION_H |
||||
|
#include <stdlib.h> |
||||
|
#include <stdio.h> |
||||
|
#include <string.h> |
||||
|
#include <stdbool.h> |
||||
|
#define UNITY_INCLUDE_CONFIG_H |
||||
|
char *stringConcatenation(char *, char *); |
||||
|
char *to_string(int); |
||||
|
char *generateCheckString(unsigned int, char *); |
||||
|
unsigned int toUnsignedInteger(char *); |
||||
|
unsigned int power(unsigned int, unsigned int); |
||||
|
bool everyCharacterIsDigit(char *); |
||||
|
bool isLetterOfAlphabet(char *); |
||||
|
double balanceToDouble(char *); |
||||
|
unsigned int calculateStringLength(char *); |
||||
|
bool charIsUpperCase(char ); |
||||
|
#endif |
@ -0,0 +1,162 @@ |
|||||
|
#include "interestCalculator.h" |
||||
|
|
||||
|
|
||||
|
void troubleshoot(int errorCode){ |
||||
|
printf("Error! The requested operation was terminated because of an issue. Here are some details about the error:\n---------------\n"); |
||||
|
|
||||
|
switch(errorCode){ |
||||
|
case 0: |
||||
|
printf("Principal amount not valid. Make sure it is a valid number over the value of zero."); |
||||
|
break; |
||||
|
case 1: |
||||
|
printf("Interest rate not valid. Make sure it is a valid number over the value of zero."); |
||||
|
break; |
||||
|
case 2: |
||||
|
printf("Duration not valid. Make sure it is a valid number over the value of zero."); |
||||
|
break; |
||||
|
case 3: |
||||
|
printf("Invalid option. Aborting."); |
||||
|
break; |
||||
|
case 4: |
||||
|
printf("Your goal cannot be smaller than your principal funds. Aborting."); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void askForSavingGoal(float principalAmount, float accInterestPerYear) { |
||||
|
char c; |
||||
|
float goal; |
||||
|
float timeForGoal; |
||||
|
|
||||
|
printf("\nWould you like to set a saving goal? [y/n]: "); |
||||
|
scanf(" %c", &c); |
||||
|
|
||||
|
if (c != 'y' && c != 'Y') { |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
printf("\nPlease enter your goal amount in €: "); |
||||
|
scanf("%f", &goal); |
||||
|
|
||||
|
if (goal < principalAmount) { |
||||
|
troubleshoot(4); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
timeForGoal = (goal - principalAmount) / accInterestPerYear; |
||||
|
printf("\nIn %.1f years you will reach your goal of %.2f.\n", timeForGoal, goal); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
float initiateInterest(float principalAmount, float interest, float time){ |
||||
|
return principalAmount*(1+(interest*time)); |
||||
|
} |
||||
|
|
||||
|
void calculateYearlyInterest(){ |
||||
|
float principalAmount; |
||||
|
float interestPerYear; |
||||
|
float timeInYears; |
||||
|
int choice; |
||||
|
|
||||
|
printf("Please enter the principal amount:"); |
||||
|
if (scanf("%f", &principalAmount) != 1 || principalAmount <= 0) { |
||||
|
troubleshoot(0); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
printf("\nPlease enter interest per year (percentage):"); |
||||
|
if (scanf("%f", &interestPerYear) != 1 || interestPerYear <= 0) { |
||||
|
troubleshoot(0); |
||||
|
return; |
||||
|
} |
||||
|
printf("\nWould you like to enter the time in [1]months or in [2]years?\n"); |
||||
|
scanf("%d",&choice); |
||||
|
if(choice==1){ |
||||
|
printf("\nPlease enter interest time in months:"); |
||||
|
if (scanf("%f", &timeInYears) != 1 || timeInYears <= 0) { |
||||
|
troubleshoot(2); |
||||
|
return; |
||||
|
} |
||||
|
timeInYears=timeInYears/12; |
||||
|
|
||||
|
}else if(choice==2){ |
||||
|
printf("\nPlease enter interest time in years:"); |
||||
|
if (scanf("%f", &timeInYears) != 1 || timeInYears <= 0) { |
||||
|
troubleshoot(2); |
||||
|
return; |
||||
|
} |
||||
|
}else{ |
||||
|
troubleshoot(2); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
float interestDecimal=interestPerYear/100; |
||||
|
|
||||
|
float result= initiateInterest(principalAmount,interestDecimal,timeInYears); |
||||
|
printf("\nAmount with the interest is %.2f€.",result); |
||||
|
askForSavingGoal(principalAmount,principalAmount*interestDecimal); |
||||
|
} |
||||
|
void calculateMonthlyInterest(){ |
||||
|
float principalAmount; |
||||
|
float interestPerMonth; |
||||
|
float timeInMonths; |
||||
|
|
||||
|
printf("Please enter the principal amount:"); |
||||
|
if (scanf("%f", &principalAmount) != 1 || principalAmount <= 0) { |
||||
|
troubleshoot(0); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
printf("\nPlease enter interest per month (percentage):"); |
||||
|
if (scanf("%f", &interestPerMonth) != 1 || interestPerMonth <= 0) { |
||||
|
troubleshoot(0); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
printf("\nPlease enter interest time in months:"); |
||||
|
if (scanf("%f", &timeInMonths) != 1 || timeInMonths <= 0) { |
||||
|
troubleshoot(2); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
float interestDecimal=interestPerMonth/100; |
||||
|
|
||||
|
float result= initiateInterest(principalAmount,interestDecimal,timeInMonths); |
||||
|
printf("\nAmount with the interest is %.2f€.",result); |
||||
|
} |
||||
|
|
||||
|
void initiateCalculator() { |
||||
|
int input; |
||||
|
char c; |
||||
|
|
||||
|
printf("Welcome to the interest calculator. Please select an option:\n" |
||||
|
"[1] Calculate yearly interest\n" |
||||
|
"[2] Calculate monthly interest\n"); |
||||
|
scanf("%d", &input); |
||||
|
|
||||
|
switch (input) { |
||||
|
case 1: |
||||
|
calculateYearlyInterest(); |
||||
|
break; |
||||
|
case 2: |
||||
|
calculateMonthlyInterest(); |
||||
|
break; |
||||
|
default: |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
printf("\nThank you for using our services. Would you like to do another calculation? [y/n]: "); |
||||
|
scanf(" %c", &c); |
||||
|
|
||||
|
if (c == 'y' || c == 'Y') { |
||||
|
initiateCalculator(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// int main(){ |
||||
|
|
||||
|
// initiateCalculator(); |
||||
|
|
||||
|
// } |
@ -0,0 +1,11 @@ |
|||||
|
#ifndef INTERESTCALCULATOR_H_ |
||||
|
#define INTERESTCALCULATOR_H_ |
||||
|
|
||||
|
#include <stdio.h> |
||||
|
|
||||
|
void calculateYearlyInterest(); |
||||
|
void calculateMonthlyInterest(); |
||||
|
void askForSavingGoal(float principalAmount, float accInterestPerYear); |
||||
|
float initiateInterest(float principalAmount, float interest, float time); |
||||
|
void troubleshoot(int errorCode); |
||||
|
#endif |
@ -0,0 +1,11 @@ |
|||||
|
#ifndef LINEREPLACER_H_ |
||||
|
#define LINEREPLACER_H_ |
||||
|
|
||||
|
#include <stdio.h> |
||||
|
#include <stdbool.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
|
||||
|
void replaceLineInFile(const char* file_name, int line, const char* new_line); //replaces the line at "line" on the file "file_name", with the new line "new_line". |
||||
|
|
||||
|
#endif |
@ -0,0 +1,88 @@ |
|||||
|
#include "loginCustomer.h" |
||||
|
|
||||
|
bool checkLogin(bool loginSuccessful) |
||||
|
{ |
||||
|
return (loginSuccessful) ? true : false; |
||||
|
} |
||||
|
|
||||
|
void collectCustomerDataForLogin(int attempts) |
||||
|
{ |
||||
|
customer_t c; |
||||
|
c.IDAsString = calloc(15+1, sizeof(char)); |
||||
|
c.password = calloc(20+1, sizeof(char)); |
||||
|
int digitCharacterFromUser, passwordCharacterFromUser; |
||||
|
int IDLengthCounter = 0, passwordLengthCounter = 0; |
||||
|
int errorResult = 0; |
||||
|
const int IDMaxLength = 16, passwordMaxLength = 21; |
||||
|
printf("Enter ID:\n"); |
||||
|
while((digitCharacterFromUser=getchar())!='\n'&&IDLengthCounter<IDMaxLength){ |
||||
|
if(digitCharacterFromUser>='0'&&digitCharacterFromUser<='9'){ |
||||
|
*(c.IDAsString+IDLengthCounter) = digitCharacterFromUser; |
||||
|
} |
||||
|
else{ |
||||
|
printf("Character entered is not a digit. Aborting.\n"); |
||||
|
exit(-1); |
||||
|
} |
||||
|
++IDLengthCounter; |
||||
|
} |
||||
|
*(c.IDAsString+IDLengthCounter) = '\0'; |
||||
|
if(IDLengthCounter>=IDMaxLength){ |
||||
|
printf("ID entered is too long. Aborting.\n"); |
||||
|
exit(-1); |
||||
|
} |
||||
|
printf("Enter password:\n"); |
||||
|
while((passwordCharacterFromUser=getchar())!='\n'&&passwordLengthCounter<passwordMaxLength){ |
||||
|
*(c.password+passwordLengthCounter) = passwordCharacterFromUser; |
||||
|
++passwordLengthCounter; |
||||
|
} |
||||
|
*(c.password+passwordLengthCounter) = '\0'; |
||||
|
|
||||
|
if(passwordLengthCounter>=passwordMaxLength){ |
||||
|
printf("Password entered is too long. Aborting.\n"); |
||||
|
exit(-1); |
||||
|
} |
||||
|
bool loginSuccessful = loginCustomer(&c); |
||||
|
unsigned int value = toUnsignedInteger(c.IDAsString); |
||||
|
free(c.IDAsString); |
||||
|
free(c.password); |
||||
|
if(loginSuccessful) { |
||||
|
int *ptr = &value; |
||||
|
menu(ptr); |
||||
|
}else if(!loginSuccessful && attempts < MAX_LOGIN_ATTEMPTS){ |
||||
|
printf("You have %d attempts left.\n", MAX_LOGIN_ATTEMPTS - attempts); |
||||
|
collectCustomerDataForLogin(++attempts); |
||||
|
}else{ |
||||
|
errorResult = errorMessage(-2); |
||||
|
if(errorResult==-2) exit(-1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
bool loginCustomer(customer_t *c) |
||||
|
{ |
||||
|
bool foundCustomerEntryInFile = false; |
||||
|
unsigned int IDAsNumber = toUnsignedInteger(c->IDAsString); |
||||
|
char *searchForThisString = generateCheckString(IDAsNumber,c->password); |
||||
|
char *lineFromCustomerFile = calloc(40,sizeof(char)); |
||||
|
int errorResult = 0; |
||||
|
FILE *readCustomerFile = fopen("CustomerData.txt", "r"); |
||||
|
if(readCustomerFile==NULL){ |
||||
|
errorResult = errorMessage(-4); |
||||
|
if(errorResult==-4) exit(-1); |
||||
|
} |
||||
|
while((fscanf(readCustomerFile,"%s",lineFromCustomerFile)!=EOF)){ |
||||
|
if(strcmp(searchForThisString,lineFromCustomerFile)==0){ |
||||
|
foundCustomerEntryInFile = true; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
free(lineFromCustomerFile); |
||||
|
if(checkLogin(foundCustomerEntryInFile)){ |
||||
|
printf("Login successful.\n"); |
||||
|
fclose(readCustomerFile); |
||||
|
return foundCustomerEntryInFile; |
||||
|
}else{ |
||||
|
errorResult = errorMessage(-1); |
||||
|
} |
||||
|
fclose(readCustomerFile); |
||||
|
return foundCustomerEntryInFile; |
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
#ifndef LOGIN_CUSTOMER_H |
||||
|
#define LOGIN_CUSTOMER_H |
||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <stdbool.h> |
||||
|
#include <string.h> |
||||
|
#include "createCustomer.h" |
||||
|
#include "customerMenu.h" |
||||
|
#include "error.h" |
||||
|
#include "customerProperties.h" |
||||
|
#define MAX_LOGIN_ATTEMPTS 3 |
||||
|
bool checkLogin(bool); |
||||
|
void collectCustomerDataForLogin(int); |
||||
|
bool loginCustomer(customer_t *); |
||||
|
#endif |
@ -1,4 +1,13 @@ |
|||||
#include <stdio.h> |
|
||||
int main(){ |
|
||||
return 0; |
|
||||
|
#include "mainMenu.h" |
||||
|
#include "employeeLogin.h" |
||||
|
#include"showGeneralInfoEmployee.h" |
||||
|
|
||||
|
void runBankManagementSystem() |
||||
|
{ |
||||
|
ageInput(); |
||||
} |
} |
||||
|
|
||||
|
int main() |
||||
|
{ |
||||
|
runBankManagementSystem(); |
||||
|
} |
@ -0,0 +1,152 @@ |
|||||
|
#include "mainMenu.h" |
||||
|
#include "employeeLogin.h" |
||||
|
#include "createEmployeeAccount.h" |
||||
|
#include "createCustomer.h" |
||||
|
#include "error.h" |
||||
|
#include "displayMenuCalculator.h" |
||||
|
|
||||
|
|
||||
|
|
||||
|
bool agePermission(int age) |
||||
|
{ |
||||
|
|
||||
|
return age >= 18; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
bool checkIfInteger(char* userInput) |
||||
|
{ |
||||
|
|
||||
|
char *endPointer; |
||||
|
|
||||
|
/*the endPointer points to the first non-integer character signaled to stop conversion*/ |
||||
|
|
||||
|
strtol(userInput, &endPointer, 10); |
||||
|
|
||||
|
return !(endPointer == userInput || *endPointer != '\0'); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
bool chooseOption(int choiceInput) |
||||
|
{ |
||||
|
|
||||
|
return !(choiceInput < 1 || choiceInput > 6); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void ageInput() |
||||
|
{ |
||||
|
|
||||
|
char* userInput = malloc(20*sizeof(char*)); |
||||
|
char* userInputPointer; |
||||
|
int input, ctr=0; |
||||
|
long age; |
||||
|
printf("\nPlease specify your age : "); |
||||
|
while((input=getchar())!='\n'){ |
||||
|
*(userInput+ctr) = input; |
||||
|
++ctr; |
||||
|
} |
||||
|
*(userInput+ctr) = '\0'; |
||||
|
while (true) |
||||
|
{ |
||||
|
/*the userInput string is changed to a number with the strtol function*/ |
||||
|
|
||||
|
age = strtol(userInput,&userInputPointer,10); |
||||
|
|
||||
|
if((checkIfInteger(userInput))&& (agePermission(age))) |
||||
|
{ |
||||
|
|
||||
|
printf("Access granted!\n\n\n\n"); |
||||
|
|
||||
|
showMenu(); |
||||
|
|
||||
|
menuInput(); |
||||
|
|
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
else if((checkIfInteger(userInput)) && !(agePermission(age))) |
||||
|
{ |
||||
|
errorMessage(-5); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
else |
||||
|
{ |
||||
|
printf("input invalid! try again!\n"); |
||||
|
|
||||
|
scanf("%s",userInput); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void menuInput() |
||||
|
{ |
||||
|
char choiceInput[20]; |
||||
|
char* choiceInputPointer; |
||||
|
int selection, input, ctr = 0; |
||||
|
|
||||
|
while((input=getchar())!='\n'){ |
||||
|
choiceInput[ctr] = input; |
||||
|
++ctr; |
||||
|
} |
||||
|
choiceInput[ctr] = '\0'; |
||||
|
|
||||
|
selection = strtol(choiceInput, &choiceInputPointer, 10); |
||||
|
|
||||
|
while (!checkIfInteger(choiceInput) || !chooseOption(selection)) |
||||
|
{ |
||||
|
printf("Input invalid! try again!\n"); |
||||
|
ctr = 0; |
||||
|
while((input=getchar())!='\n'){ |
||||
|
choiceInput[ctr] = input; |
||||
|
++ctr; |
||||
|
} |
||||
|
choiceInput[ctr] = '\0'; |
||||
|
selection = strtol(choiceInput, &choiceInputPointer, 10); |
||||
|
} |
||||
|
switch(selection) |
||||
|
{ |
||||
|
case 1 : collectCustomerDataForLogin(0); |
||||
|
break; |
||||
|
|
||||
|
case 2 : collectCustomerProperties(); |
||||
|
break; |
||||
|
|
||||
|
case 3 : getEmployeeAccessCode(); |
||||
|
break; |
||||
|
|
||||
|
case 4 : getNewEmployeeCredentials(); |
||||
|
break; |
||||
|
|
||||
|
case 5 : displayMenuCalculator('c'); |
||||
|
break; |
||||
|
|
||||
|
case 6 : printf("\e[1;1H\e[2J"); |
||||
|
printf("\nsee you next time !\n\n"); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void showMenu() |
||||
|
{ |
||||
|
|
||||
|
printf("\t\t\t\t\t\t\t Welcome to Bank Manager!"); |
||||
|
printf("\n\n\n\n\t\t\t\t\t\tPlease select one of the following functions!"); |
||||
|
printf("\n\n\n\n\t\t\t\t\t\t ->Login as an existing costumer."); |
||||
|
printf("\n\n\t\t\t\t\t\t ->Register as a new costumer."); |
||||
|
printf("\n\n\t\t\t\t\t\t ->Login as an Employee."); |
||||
|
printf("\n\n\t\t\t\t\t\t ->Register as an Employee."); |
||||
|
printf("\n\n\t\t\t\t\t\t ->Calculator"); |
||||
|
printf("\n\n\t\t\t\t\t\t\t\t ->Exit.\n"); |
||||
|
printf("\n\n\n\n\n Selection :\n"); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
@ -0,0 +1,22 @@ |
|||||
|
#ifndef MAINMENU_H_ |
||||
|
#define MAINMENU_H_ |
||||
|
|
||||
|
#include<stdio.h> |
||||
|
#include<stdlib.h> |
||||
|
#include<stdbool.h> |
||||
|
#include<string.h> |
||||
|
#include "loginCustomer.h" |
||||
|
|
||||
|
#define credentialLength 20 |
||||
|
|
||||
|
bool agePermission(int age); |
||||
|
bool checkIfInteger(char* userInput); |
||||
|
bool chooseOption(int choiceInput); |
||||
|
|
||||
|
void ageInput(); |
||||
|
void menuInput(); |
||||
|
void showMenu(); |
||||
|
void menuInput(); |
||||
|
|
||||
|
#endif |
||||
|
|
@ -0,0 +1,29 @@ |
|||||
|
#include "requestLoan.h" |
||||
|
const int a = 1; |
||||
|
int option1 = 1000; |
||||
|
int option2 = 2500; |
||||
|
int option3 = 5000; |
||||
|
char currency[] = "Euro"; |
||||
|
int allow() //int allow() is helpful for indirectly testing void requestLoan() |
||||
|
{ |
||||
|
if (a == 1) |
||||
|
{ |
||||
|
return 1; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void requestLoan() |
||||
|
{ |
||||
|
if (allow() == 1) //only if int allow() returns 1, void requestLoan() will display the desired output |
||||
|
{ |
||||
|
printf(" Please select a loan Package: \n"); |
||||
|
printf(" \n"); |
||||
|
printf(" \n"); |
||||
|
printf(" %d %s\n", option1, currency); |
||||
|
printf(" %d %s\n", option2, currency); |
||||
|
printf(" %d %s\n", option3, currency); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
@ -0,0 +1,5 @@ |
|||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
|
||||
|
void requestLoan(); |
||||
|
int allow(); |
@ -0,0 +1,112 @@ |
|||||
|
#include "sendMoney.h" |
||||
|
#include "depositMoney.h" |
||||
|
#include "withdrawMoney.h" |
||||
|
#include "currencyExchange.h" |
||||
|
#include "currentCustomerAccountBalance.h" |
||||
|
#include "updateCustomerAccountBalance.h" |
||||
|
|
||||
|
|
||||
|
|
||||
|
void showBalance(int customerID){ |
||||
|
float balance=getAvailableAccountBalance(customerID); |
||||
|
printf("\n:.:.:.:.:.:"); |
||||
|
printf("\nYour current balance is %.2f.\n",balance); |
||||
|
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){ |
||||
|
char c; |
||||
|
printf("\nWould you like to see your remaining balance? [y] yes [any] no\n"); |
||||
|
scanf(" %c",&c); |
||||
|
if(c=='y' || c=='Y'){ |
||||
|
showBalance(customerID); |
||||
|
} |
||||
|
return; |
||||
|
} |
||||
|
bool sendMoney(int customerID) { |
||||
|
float available_account_balance = getAvailableAccountBalance(customerID); |
||||
|
float amount_to_send; |
||||
|
int recipient_id; |
||||
|
|
||||
|
showBalance(customerID); |
||||
|
printf("\nHow much would you like to send?\n"); |
||||
|
scanf("%f", &amount_to_send); |
||||
|
if (amount_to_send > 0 && amount_to_send < available_account_balance) { |
||||
|
printf("\nYour input was %.2f€. Please enter the recipient id.\n", amount_to_send); |
||||
|
scanf("%d", &recipient_id); |
||||
|
if (recipient_id > 1000) { |
||||
|
bool recipient_exists = checkCustomerExists(recipient_id); |
||||
|
if (recipient_exists) { |
||||
|
if (recipient_id == customerID) { |
||||
|
printf("\nYou cannot send money to yourself. Aborting. \n"); |
||||
|
return false; |
||||
|
} else { |
||||
|
if (withdrawSpecificAmount(customerID, amount_to_send)) { |
||||
|
if (depositSpecificAmount(recipient_id, amount_to_send)) { |
||||
|
askToConvert(amount_to_send, recipient_id); |
||||
|
askToShowBalance(customerID); |
||||
|
return true; |
||||
|
} else { |
||||
|
printf("\nSomething went wrong with the transfer. Please contact staff."); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
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, amount_to_send + TRANSFER_FEE)) { |
||||
|
askToConvert(amount_to_send, recipient_id); |
||||
|
askToShowBalance(customerID); |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
printf("\nThe ID you have entered is not valid. Aborting. \n"); |
||||
|
} |
||||
|
} else { |
||||
|
// error |
||||
|
return false; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
@ -0,0 +1,14 @@ |
|||||
|
#ifndef SENDMONEY_H |
||||
|
#define SENDMONEY_H |
||||
|
#include <stdlib.h> |
||||
|
#include <stdio.h> |
||||
|
#include <stdbool.h> |
||||
|
#include <string.h> |
||||
|
|
||||
|
#define TRANSFER_FEE 0.8 |
||||
|
void showBalance(int customerID); |
||||
|
float askToConvert(float input, int customerID); |
||||
|
void askToShowBalance(int customerID); |
||||
|
bool sendMoney(int customerID); |
||||
|
|
||||
|
#endif // SENDMONEY_H |
@ -0,0 +1,131 @@ |
|||||
|
#include "showGeneralInfoEmployee.h" |
||||
|
|
||||
|
//int checkUser() is helpful for unittesting showGeneralInfoEmployee() |
||||
|
int checkUser(char username[length], char password[length]) |
||||
|
{ |
||||
|
if(strcmp(username,"Atharva")==0 && strcmp(password,"Atharvafdai7514")==0) |
||||
|
{ |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
if(strcmp(username,"Can")==0 && strcmp(password,"BlooMaskfdlt3817")==0) |
||||
|
{ |
||||
|
return 2; |
||||
|
} |
||||
|
|
||||
|
if(strcmp(username,"Haytham")==0 && strcmp(password,"TimoDLfdai7207")==0) |
||||
|
{ |
||||
|
return 3; |
||||
|
} |
||||
|
|
||||
|
if(strcmp(username,"Julius")==0 && strcmp(password,"Insertcatfdai7057")==0) |
||||
|
{ |
||||
|
return 4; |
||||
|
} |
||||
|
|
||||
|
if(strcmp(username,"Mohamed")==0 && strcmp(password,"MDfdai6618")==0) |
||||
|
{ |
||||
|
return 5; |
||||
|
} |
||||
|
|
||||
|
if(strcmp(username,"Shivam")==0 && strcmp(password,"Schivam007fdlt3781")==0) |
||||
|
{ |
||||
|
return 6; |
||||
|
} |
||||
|
|
||||
|
else |
||||
|
{ |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void showGeneralInfoEmployee(char id[length], char password[length]) |
||||
|
{ |
||||
|
// "If Statements" check, whether the username and password match. |
||||
|
|
||||
|
if(checkUser(id, password) == 1) |
||||
|
{ |
||||
|
printf(" Welcome Atharva\n"); |
||||
|
printf(" Clearance: 3\n"); |
||||
|
printf(" Welcome Atharva\n"); |
||||
|
printf(" Clearance: 3\n"); |
||||
|
printf("\n"); |
||||
|
printf("\n"); |
||||
|
printf(" ->Review new customer applications.\n"); |
||||
|
} |
||||
|
|
||||
|
if(checkUser(id, password) == 2) |
||||
|
{ |
||||
|
printf(" Welcome Can\n"); |
||||
|
printf(" Clearance: 3\n"); |
||||
|
printf(" Welcome Can\n"); |
||||
|
printf(" Clearance: 3\n"); |
||||
|
printf("\n"); |
||||
|
printf("\n"); |
||||
|
printf(" ->Review new customer applications.\n"); |
||||
|
printf(" ->Review new customer applications.\n"); |
||||
|
} |
||||
|
|
||||
|
if(checkUser(id, password) == 3) |
||||
|
{ |
||||
|
printf(" Welcome Haytham\n"); |
||||
|
printf(" Clearance: 2\n"); |
||||
|
printf(" Welcome Haytham\n"); |
||||
|
printf(" Clearance: 2\n"); |
||||
|
printf("\n"); |
||||
|
printf("\n"); |
||||
|
printf(" ->Review new customer applications.\n"); |
||||
|
printf(" ->Review loan applications.\n"); |
||||
|
printf(" ->Review new customer applications.\n"); |
||||
|
printf(" ->Review loan applications.\n"); |
||||
|
} |
||||
|
|
||||
|
if(checkUser(id, password) == 4) |
||||
|
{ |
||||
|
printf(" Welcome Julius\n"); |
||||
|
printf(" Clearance: 2\n"); |
||||
|
printf(" Welcome Julius\n"); |
||||
|
printf(" Clearance: 2\n"); |
||||
|
printf("\n"); |
||||
|
printf("\n"); |
||||
|
printf(" ->Review new customer applications.\n"); |
||||
|
printf(" ->Review loan applications.\n"); |
||||
|
printf(" ->Review new customer applications.\n"); |
||||
|
printf(" ->Review loan applications.\n"); |
||||
|
} |
||||
|
|
||||
|
if(checkUser(id, password) == 5) |
||||
|
{ |
||||
|
printf(" Welcome Mohamed\n"); |
||||
|
printf(" Clearance: 1\n"); |
||||
|
printf(" Welcome Mohamed\n"); |
||||
|
printf(" Clearance: 1\n"); |
||||
|
printf("\n"); |
||||
|
printf("\n"); |
||||
|
printf(" ->Review new customer applications.\n"); |
||||
|
printf(" ->Review loan applications.\n"); |
||||
|
printf(" ->Terminate account.\n"); |
||||
|
printf(" ->Review new customer applications.\n"); |
||||
|
printf(" ->Review loan applications.\n"); |
||||
|
printf(" ->Terminate account.\n"); |
||||
|
} |
||||
|
|
||||
|
if(checkUser(id, password) == 6) |
||||
|
{ |
||||
|
printf(" Welcome Shivam\n"); |
||||
|
printf(" Clearance: 1\n"); |
||||
|
printf(" Welcome Shivam\n"); |
||||
|
printf(" Clearance: 1\n"); |
||||
|
printf("\n"); |
||||
|
printf("\n"); |
||||
|
printf(" ->Review new customer applications.\n"); |
||||
|
printf(" ->Review loan applications.\n"); |
||||
|
printf(" ->Terminate account.\n"); |
||||
|
printf(" ->Review new customer applications.\n"); |
||||
|
printf(" ->Review loan applications.\n"); |
||||
|
printf(" ->Terminate account.\n"); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,12 @@ |
|||||
|
#ifndef SHOWGENERALINFOEMPLOYEE_H |
||||
|
#define SHOWGENERALINFOEMPLOYEE_H |
||||
|
|
||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
|
||||
|
#define length 20 |
||||
|
|
||||
|
int checkUser(char username[length], char password[length]); |
||||
|
void showGeneralInfoEmployee(char id[length], char password[length]); |
||||
|
#endif // SHOWGENERALINFOEMPLOYEE_H |
@ -0,0 +1,169 @@ |
|||||
|
#include "updateCustomerAccountBalance.h" |
||||
|
#include "lineReplacer.h" |
||||
|
#include "_file_information.h" |
||||
|
|
||||
|
void troubleShoot(int errorCode){ |
||||
|
printf("Error! The requested operation was terminated because of an issue. Here are some details about the error:\n---------------\n"); |
||||
|
|
||||
|
switch(errorCode){ |
||||
|
case 0: |
||||
|
printf("Requested file could not be opened. Are you sure it exists or that the program has the required permissions?"); |
||||
|
break; |
||||
|
case 1: |
||||
|
printf("A temporary file could not be generated. Are you sure the bank management system has the required authorization to create new files?"); |
||||
|
break; |
||||
|
case 2: |
||||
|
printf("Replacement of the old file failed. Are you sure the bank management system has the required authorization to delete files?"); |
||||
|
break; |
||||
|
case 3: |
||||
|
printf("Renaming of a file failed. Are you sure the bank management system has the required authorization to rename files?"); |
||||
|
break; |
||||
|
case 4: |
||||
|
printf("Could not find the customer. Please contact customer support."); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void replaceLineInFile(const char* file_name, int line, const char* new_line){ |
||||
|
FILE* file = fopen(file_name, "r"); |
||||
|
if (file == NULL) { |
||||
|
troubleShoot(0); |
||||
|
return; |
||||
|
} |
||||
|
char current_string[1024]; |
||||
|
int current_line = 1; |
||||
|
char *temp_file_name = "temp.txt"; |
||||
|
FILE* temp_file = fopen(temp_file_name, "w"); |
||||
|
if (temp_file == NULL) { |
||||
|
troubleShoot(1); |
||||
|
fclose(file); |
||||
|
return; |
||||
|
} |
||||
|
while (fgets(current_string, sizeof(current_string), file) != NULL) { |
||||
|
if (current_line == line) { |
||||
|
fprintf(temp_file, "%s", new_line); |
||||
|
fputs("\n", temp_file); |
||||
|
} else { |
||||
|
fprintf(temp_file, "%s", current_string); |
||||
|
} |
||||
|
current_line++; |
||||
|
} |
||||
|
fclose(file); |
||||
|
fclose(temp_file); |
||||
|
if(remove(file_name)!=0){ |
||||
|
troubleShoot(2); |
||||
|
} // Remove the original file |
||||
|
if(rename(temp_file_name, file_name)!=0){ |
||||
|
troubleShoot(3); |
||||
|
} // Rename the temp file to the original file |
||||
|
} |
||||
|
|
||||
|
void replaceBalanceInString(float replacementBalance, int currentLine) { |
||||
|
char newBalanceLine[MAX_LENGTH] = "balance="; |
||||
|
char balance_as_string[MAX_LENGTH]; |
||||
|
sprintf(balance_as_string, "%g", replacementBalance); //converts replacement balance to string |
||||
|
strcat(newBalanceLine, balance_as_string); |
||||
|
replaceLineInFile(CUSTOMER_DATA_FILE,currentLine,newBalanceLine); |
||||
|
} |
||||
|
|
||||
|
bool updateAvailableAccountBalance(int user_id, float newBalance){ |
||||
|
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", user_id); // converts user_id to string |
||||
|
strcat(stringID, user_id_as_string); |
||||
|
|
||||
|
FILE *file = fopen(CUSTOMER_DATA_FILE, "r+"); |
||||
|
if (file == NULL) { |
||||
|
troubleShoot(0); |
||||
|
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){ |
||||
|
replaceBalanceInString(newBalance,currentLine); |
||||
|
return true; |
||||
|
}else{ |
||||
|
troubleShoot(4); |
||||
|
} |
||||
|
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 |
||||
|
/* |
||||
|
int main(int argc, char *argv[]) |
||||
|
{ |
||||
|
updateAvailableAccountBalance(1327,70); |
||||
|
return 0; |
||||
|
} |
||||
|
*/ |
@ -0,0 +1,15 @@ |
|||||
|
#ifndef UpdateCustomerAccountBalance_H |
||||
|
#define UpdateCustomerAccountBalance_H |
||||
|
|
||||
|
#include <stdio.h> |
||||
|
#include <stdbool.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
|
||||
|
|
||||
|
|
||||
|
bool updateAvailableAccountBalance(int user_id, float newBalance); |
||||
|
bool checkCustomerExists(int customerID); |
||||
|
void replaceBalanceInString(float replacementBalance, int currentLine); |
||||
|
|
||||
|
#endif |
@ -0,0 +1,102 @@ |
|||||
|
#include "withdrawMoney.h" |
||||
|
#include "updateCustomerAccountBalance.h" |
||||
|
#include "currentCustomerAccountBalance.h" |
||||
|
|
||||
|
|
||||
|
void notifyCustomer(float amountToWithdraw, float remainingAccountBalance, int user_id) { |
||||
|
char c; |
||||
|
|
||||
|
printf("You have successfully withdrawn %.2f €.\n", amountToWithdraw); |
||||
|
printf("Remaining account balance: %.2f €\n\n", remainingAccountBalance); |
||||
|
printf("Would you like to do another withdrawal? [y] yes [any] no\n"); |
||||
|
scanf(" %c", &c); |
||||
|
|
||||
|
if (c=='y'||c=='Y') { |
||||
|
withdraw(user_id); |
||||
|
}else{ |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
float initiateWithdraw(float amountToWithdraw, float availableAccountBalance) { |
||||
|
float remainingAccountBalance = (availableAccountBalance - amountToWithdraw); |
||||
|
|
||||
|
return remainingAccountBalance; |
||||
|
} |
||||
|
|
||||
|
bool withdraw(int user_id) { |
||||
|
float amountToWithdraw; |
||||
|
char tryDifferentAmount; |
||||
|
float remainingAccountBalance; |
||||
|
bool updateSuccess = false; |
||||
|
|
||||
|
float availableAccountBalance = getAvailableAccountBalance(user_id); |
||||
|
|
||||
|
printf("\n:.:.:.:.:.:"); |
||||
|
printf("\nYour current balance is %.2f.\n",availableAccountBalance); |
||||
|
printf(":.:.:.:.:.:\n"); |
||||
|
|
||||
|
printf("Enter amount to withdraw: "); |
||||
|
scanf("%f", &amountToWithdraw); |
||||
|
|
||||
|
|
||||
|
if (amountToWithdraw > 0) { |
||||
|
if (amountToWithdraw <= availableAccountBalance) { |
||||
|
|
||||
|
if(amountToWithdraw>MAX_AMOUNT){ |
||||
|
printf("\nYou cannot withdraw more than %d€.",MAX_AMOUNT); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
remainingAccountBalance = initiateWithdraw(amountToWithdraw, availableAccountBalance); |
||||
|
updateSuccess = updateAvailableAccountBalance(user_id, remainingAccountBalance); |
||||
|
if( updateSuccess ) { |
||||
|
notifyCustomer(amountToWithdraw, remainingAccountBalance, user_id); |
||||
|
} |
||||
|
else { |
||||
|
printf("Some error occured! Sorry for the inconvenience caused.\n"); |
||||
|
} |
||||
|
return updateSuccess; |
||||
|
|
||||
|
} |
||||
|
else { |
||||
|
printf("You don't have sufficient money to withdraw. Do you want to try different amount?\n[y]: Yes, any other key : exit"); |
||||
|
scanf("%c", &tryDifferentAmount); |
||||
|
if (tryDifferentAmount == 'Y' || tryDifferentAmount == 'y') { |
||||
|
withdraw(user_id); |
||||
|
} |
||||
|
else { |
||||
|
//showAllMenuEntries(); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
else { |
||||
|
printf("Invalid Input! Please try again.\n"); |
||||
|
withdraw(user_id); |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
bool withdrawSpecificAmount(int user_id, float amountToWithdraw) { |
||||
|
float remainingAccountBalance; |
||||
|
|
||||
|
float availableAccountBalance = getAvailableAccountBalance(user_id); |
||||
|
|
||||
|
if (amountToWithdraw > 0) { |
||||
|
if (amountToWithdraw <= availableAccountBalance) { |
||||
|
remainingAccountBalance = initiateWithdraw(amountToWithdraw, availableAccountBalance); |
||||
|
if (updateAvailableAccountBalance(user_id, remainingAccountBalance)) { |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// int main(){ |
||||
|
// withdraw(1234); |
||||
|
// return 1; |
||||
|
// } |
@ -0,0 +1,14 @@ |
|||||
|
#ifndef WITHDRAWMONEY_H_ |
||||
|
#define WITHDRAWMONEY_H_ |
||||
|
|
||||
|
#include <stdio.h> |
||||
|
#include <stdbool.h> |
||||
|
|
||||
|
#define MAX_AMOUNT 10000 |
||||
|
|
||||
|
bool withdraw(int user_id); |
||||
|
float initiateWithdraw(float amountToWithdraw, float availableAccountBalance); |
||||
|
void notifyCustomer(float amountToWithdraw, float remainingAccountBalance, int user_id); |
||||
|
bool withdrawSpecificAmount(int user_id, float amountToWithdraw); |
||||
|
|
||||
|
#endif |
@ -1,9 +1,6 @@ |
|||||
# Bankmanagement-System |
|
||||
|
|
||||
- Can Hacioglu, Fdlt3817 |
|
||||
|
- Can Hacioglu, fdlt3817 |
||||
- Atharva Kishor Naik, fdai7514 |
- Atharva Kishor Naik, fdai7514 |
||||
- Julius Philipp Engel, fdai7057 |
- Julius Philipp Engel, fdai7057 |
||||
- Shivam Chaudhary, fdlt3781 |
- Shivam Chaudhary, fdlt3781 |
||||
- Mohamed Yahya Dahi, fdai6618 |
- Mohamed Yahya Dahi, fdai6618 |
||||
- Haytham Daoula, fdai7207 |
|
||||
|
|
||||
|
- Haytham Daoula, fdai7207 |
@ -0,0 +1,29 @@ |
|||||
|
#include <unity.h> |
||||
|
#include <limits.h> |
||||
|
#include <math.h> |
||||
|
#include "../src/helperFunctions.c" |
||||
|
#include "../src/error.c" |
||||
|
#include "../src/createCustomer.c" |
||||
|
|
||||
|
void setUp(){} |
||||
|
void tearDown(){} |
||||
|
|
||||
|
void test_generateID(){ |
||||
|
|
||||
|
const int test_values = USHRT_MAX; |
||||
|
|
||||
|
/*initialize blocks by calling generateID()*/ |
||||
|
int *numbers = calloc(test_values, sizeof(int)); |
||||
|
for(int i=0;i<test_values;++i) |
||||
|
{ |
||||
|
*(numbers+i) = generateID(); |
||||
|
//printf("%d\n", *(numbers+i)); |
||||
|
} |
||||
|
|
||||
|
/*assertions, range checking*/ |
||||
|
int delta = 5000000, expected = 5000000; |
||||
|
for(int i=0;i<test_values;++i) |
||||
|
{ |
||||
|
TEST_ASSERT_INT_WITHIN(delta, expected,*(numbers+i)); |
||||
|
} |
||||
|
} |
@ -0,0 +1,81 @@ |
|||||
|
#include <unity.h> |
||||
|
#include <time.h> |
||||
|
#include <stdlib.h> |
||||
|
#include "../src/error.c" |
||||
|
|
||||
|
void setUp(){} |
||||
|
void tearDown(){} |
||||
|
|
||||
|
|
||||
|
void test_error() |
||||
|
{ |
||||
|
/*arrange*/ |
||||
|
srand(time(0)); |
||||
|
int bound = 1000; |
||||
|
int invalidErrorCodes_1[bound]; |
||||
|
int invalidErrorCodesLarge_2[bound]; |
||||
|
int invalidErrorCodesLargest_3[bound]; |
||||
|
|
||||
|
int validErrorCodeUnsuccessfulLogin[bound]; |
||||
|
int validErrorCodeMaximumNumberOfAttempts[bound]; |
||||
|
int validErrorCodeNoMenuEntryForNumber[bound]; |
||||
|
/*new test cases*/ |
||||
|
int validErrorCodeNoCustomerDataFile[bound]; |
||||
|
int validErrorCodeTooYoung[bound]; |
||||
|
int validErrorCodeCreatingFile[bound]; |
||||
|
int validErrorCodeForenameTooLong[bound]; |
||||
|
int validErrorCodeSurnameTooLong[bound]; |
||||
|
int validErrorCodePasswordTooLong[bound]; |
||||
|
|
||||
|
int validErrorCodeInvalidCharacterForename[bound]; |
||||
|
int validErrorCodeInvalidCharacterSurname[bound]; |
||||
|
int validErrorCodeTooManyDigits[bound]; |
||||
|
|
||||
|
|
||||
|
for(int i=0;i<bound;++i){ |
||||
|
/*1000 numbers in the range from 1 to 2000 */ |
||||
|
invalidErrorCodes_1[i] = rand() % 2000 + 1; |
||||
|
/*1000 numbers in the range from 1000.000 to 100.999.999*/ |
||||
|
invalidErrorCodesLarge_2[i] = (rand() % 100000000) + 1000000; |
||||
|
/*1000 numbers in the range from 1.000.000.000 to 2.000.000.000*/ |
||||
|
invalidErrorCodesLargest_3[i] = (rand() % 1000000001) + 1000000000 ; |
||||
|
/*1000 times -1 in array*/ |
||||
|
validErrorCodeUnsuccessfulLogin[i] = -1; |
||||
|
/*1000 times -2 in array*/ |
||||
|
validErrorCodeMaximumNumberOfAttempts[i] = -2; |
||||
|
/*1000 times -3 in array*/ |
||||
|
validErrorCodeNoMenuEntryForNumber[i] = -3; |
||||
|
validErrorCodeNoCustomerDataFile[i] = -4; |
||||
|
validErrorCodeTooYoung[i] = -5; |
||||
|
validErrorCodeCreatingFile[i] = -6; |
||||
|
validErrorCodeForenameTooLong[i] = -7; |
||||
|
validErrorCodeSurnameTooLong[i] = -8; |
||||
|
validErrorCodePasswordTooLong[i] = -9; |
||||
|
validErrorCodeInvalidCharacterForename[i] = -10; |
||||
|
validErrorCodeInvalidCharacterSurname[i] = -11; |
||||
|
validErrorCodeTooManyDigits[i] = -12; |
||||
|
} |
||||
|
|
||||
|
/*act and assertions for invalid error codes*/ |
||||
|
for(int i=0;i<bound;++i){ |
||||
|
TEST_ASSERT_EQUAL_INT(0,errorMessage(invalidErrorCodes_1[i])); |
||||
|
TEST_ASSERT_EQUAL_INT(0,errorMessage(invalidErrorCodesLarge_2[i])); |
||||
|
TEST_ASSERT_EQUAL_INT(0,errorMessage(invalidErrorCodesLargest_3[i])); |
||||
|
} |
||||
|
/*act and assertions for valid error codes*/ |
||||
|
for(int i=0;i<bound;++i){ |
||||
|
TEST_ASSERT_EQUAL_INT(-1, errorMessage(validErrorCodeUnsuccessfulLogin[i])); |
||||
|
TEST_ASSERT_EQUAL_INT(-2, errorMessage(validErrorCodeMaximumNumberOfAttempts[i])); |
||||
|
TEST_ASSERT_EQUAL_INT(-3, errorMessage(validErrorCodeNoMenuEntryForNumber[i])); |
||||
|
/*new test cases*/ |
||||
|
TEST_ASSERT_EQUAL_INT(-4, errorMessage(validErrorCodeNoCustomerDataFile[i])); |
||||
|
TEST_ASSERT_EQUAL_INT(-5, errorMessage(validErrorCodeTooYoung[i])); |
||||
|
TEST_ASSERT_EQUAL_INT(-6, errorMessage(validErrorCodeCreatingFile[i])); |
||||
|
TEST_ASSERT_EQUAL_INT(-7, errorMessage(validErrorCodeForenameTooLong[i])); |
||||
|
TEST_ASSERT_EQUAL_INT(-8, errorMessage(validErrorCodeSurnameTooLong[i])); |
||||
|
TEST_ASSERT_EQUAL_INT(-9, errorMessage(validErrorCodePasswordTooLong[i])); |
||||
|
TEST_ASSERT_EQUAL_INT(-10, errorMessage(validErrorCodeInvalidCharacterForename[i])); |
||||
|
TEST_ASSERT_EQUAL_INT(-11, errorMessage(validErrorCodeInvalidCharacterSurname[i])); |
||||
|
TEST_ASSERT_EQUAL_INT(-12, errorMessage(validErrorCodeTooManyDigits[i])); |
||||
|
} |
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
#include <unity.h> |
||||
|
#include "../src/loginCustomer.c" |
||||
|
#include "../src/customerMenu.c" |
||||
|
#include "../src/helperFunctions.c" |
||||
|
#include "../src/requestLoan.c" |
||||
|
#include "../src/error.c" |
||||
|
#include "../src/sendMoney.c" |
||||
|
#include "../src/withdrawMoney.c" |
||||
|
#include "../src/depositMoney.c" |
||||
|
#include "../src/currencyExchange.c" |
||||
|
#include "../src/updateCustomerAccountBalance.c" |
||||
|
#include "../src/currentCustomerAccountBalance.c" |
||||
|
|
||||
|
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])); |
||||
|
} |
||||
|
} |
@ -0,0 +1,122 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "../src/calculatorAdd.c" |
||||
|
|
||||
|
|
||||
|
|
||||
|
// Note: |
||||
|
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
||||
|
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
||||
|
|
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test1_calculatorAdd(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 26.24; |
||||
|
num2 = 23.22; |
||||
|
actual = calculatorAdd(num1, num2); //Act |
||||
|
expected = num1 + num2; |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test2_calculatorAdd(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 56.24; |
||||
|
num2 = 233.22; |
||||
|
actual = calculatorAdd(num1, num2); //Act |
||||
|
expected = num1 + num2; |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test3_calculatorAdd(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 1226.24; |
||||
|
num2 = 323.22; |
||||
|
actual = calculatorAdd(num1, num2); //Act |
||||
|
expected = num1 + num2; |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test4_calculatorAdd(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 2623.24; |
||||
|
num2 = 2323.22; |
||||
|
actual = calculatorAdd(num1, num2); //Act |
||||
|
expected = num1 + num2; |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test5_calculatorAdd(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 2435.24; |
||||
|
num2 = 23423.22; |
||||
|
actual = calculatorAdd(num1, num2); //Act |
||||
|
expected = num1 + num2; |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test6_calculatorAdd(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 4534.24; |
||||
|
num2 = 2221.22; |
||||
|
actual = calculatorAdd(num1, num2); //Act |
||||
|
expected = num1 + num2; |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test7_calculatorAdd(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 26322.24; |
||||
|
num2 = 2332.222; |
||||
|
actual = calculatorAdd(num1, num2); //Act |
||||
|
expected = num1 + num2; |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test8_calculatorAdd(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 26132.24; |
||||
|
num2 = 2331122.222; |
||||
|
actual = calculatorAdd(num1, num2); //Act |
||||
|
expected = num1 + num2; |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test9_calculatorAdd(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 6322.24; |
||||
|
num2 = 21232.2322; |
||||
|
actual = calculatorAdd(num1, num2); //Act |
||||
|
expected = num1 + num2; |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test10_calculatorAdd(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 1234.456; |
||||
|
num2 = 654.4321; |
||||
|
actual = calculatorAdd(num1, num2); //Act |
||||
|
expected = num1 + num2; |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,117 @@ |
|||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "../src/calculatorDivide.c" |
||||
|
|
||||
|
// Note: |
||||
|
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
||||
|
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
||||
|
|
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test1_calculatorDivide(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 26.24; |
||||
|
num2 = 23.22; |
||||
|
expected = num1 / num2; |
||||
|
actual = calculatorDivide(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test2_calculatorDivide(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 2236.24; |
||||
|
num2 = 2123.22; |
||||
|
expected = num1 / num2; |
||||
|
actual = calculatorDivide(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test3_calculatorDivide(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 623.2; |
||||
|
num2 = 23.22; |
||||
|
expected = num1 / num2; |
||||
|
actual = calculatorDivide(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test4_calculatorDivide(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 234.7; |
||||
|
num2 = 124.2; |
||||
|
expected = num1 / num2; |
||||
|
actual = calculatorDivide(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test5_calculatorDivide(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 26207.2; |
||||
|
num2 = 278.23; |
||||
|
expected = num1 / num2; |
||||
|
actual = calculatorDivide(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test6_calculatorDivide(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 111; |
||||
|
num2 = 21; |
||||
|
expected = num1 / num2; |
||||
|
actual = calculatorDivide(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test7_calculatorDivide(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 167; |
||||
|
num2 = 23.22; |
||||
|
expected = num1 / num2; |
||||
|
actual = calculatorDivide(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test8_calculatorDivide(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 26124; |
||||
|
num2 = 23022; |
||||
|
expected = num1 / num2; |
||||
|
actual = calculatorDivide(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test9_calculatorDivide(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 1234; |
||||
|
num2 = 4321; |
||||
|
expected = num1 / num2; |
||||
|
actual = calculatorDivide(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test10_calculatorDivide(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 2345; |
||||
|
num2 = 123.7; |
||||
|
expected = num1 / num2; |
||||
|
actual = calculatorDivide(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
@ -0,0 +1,79 @@ |
|||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "../src/calculatorFactorial.c" |
||||
|
|
||||
|
// Note: |
||||
|
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
||||
|
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
||||
|
|
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test1_calculatorFactorial(void) |
||||
|
{ |
||||
|
int num, actual, expected; //Arrange |
||||
|
num = 1; |
||||
|
expected = 1; |
||||
|
actual = calculatorFactorial(num); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test2_calculatorFactorial(void) |
||||
|
{ |
||||
|
int num, actual, expected; //Arrange |
||||
|
num = 0; |
||||
|
expected = 1; |
||||
|
actual = calculatorFactorial(num); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test3_calculatorFactorial(void) |
||||
|
{ |
||||
|
int num, actual, expected; //Arrange |
||||
|
num = 3; |
||||
|
expected = 6; |
||||
|
actual = calculatorFactorial(num); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test4_calculatorFactorial(void) |
||||
|
{ |
||||
|
int num, actual, expected; //Arrange |
||||
|
num = 5; |
||||
|
expected = 120; |
||||
|
actual = calculatorFactorial(num); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test5_calculatorFactorial(void) |
||||
|
{ |
||||
|
int num, actual, expected; //Arrange |
||||
|
num = 8; |
||||
|
expected = 40320; |
||||
|
actual = calculatorFactorial(num); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test6_calculatorFactorial(void) |
||||
|
{ |
||||
|
int num, actual, expected; //Arrange |
||||
|
num = 11; |
||||
|
expected = 39916800; |
||||
|
actual = calculatorFactorial(num); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test7_calculatorFactorial(void) |
||||
|
{ |
||||
|
int num, actual, expected; //Arrange |
||||
|
num = 10; |
||||
|
expected = 3628800; |
||||
|
actual = calculatorFactorial(num); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); //Assert |
||||
|
} |
@ -0,0 +1,25 @@ |
|||||
|
|
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "../src/calculatorGetUserInput.c" |
||||
|
|
||||
|
// Note: |
||||
|
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
||||
|
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_calculatorGetUserInput_NeedToImplement(void) |
||||
|
{ |
||||
|
int actual, expected; //Arrange |
||||
|
expected = 1; |
||||
|
actual = allowOnly(); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual);//Assert |
||||
|
} |
@ -0,0 +1,27 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "../src/calculatorGetUserInputFactorial.c" |
||||
|
|
||||
|
// Note: |
||||
|
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
||||
|
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_calculatorGetUserInputFactorial(void) |
||||
|
{ |
||||
|
int actual, expected; //Arrange |
||||
|
expected = 1; |
||||
|
actual = allowWhen(); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,120 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "../src/calculatorMultiply.c" |
||||
|
|
||||
|
// Note: |
||||
|
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
||||
|
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
||||
|
|
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test1_calculatorMultiply(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 26.24; |
||||
|
num2 = 23.22; |
||||
|
expected = num1 * num2; |
||||
|
actual = calculatorMultiply(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test2_calculatorMultiply(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 56.24; |
||||
|
num2 = 233.22; |
||||
|
expected = num1 * num2; |
||||
|
actual = calculatorMultiply(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test3_calculatorMultiply(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 1226.24; |
||||
|
num2 = 323.22; |
||||
|
expected = num1 * num2; |
||||
|
actual = calculatorMultiply(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test4_calculatorMultiply(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 2623.24; |
||||
|
num2 = 2323.22; |
||||
|
expected = num1 * num2; |
||||
|
actual = calculatorMultiply(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test5_calculatorMultiply(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 2435.24; |
||||
|
num2 = 23423.22; |
||||
|
expected = num1 * num2; |
||||
|
actual = calculatorMultiply(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test6_calculatorMultiply(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 4534.24; |
||||
|
num2 = 2221.22; |
||||
|
expected = num1 * num2; |
||||
|
actual = calculatorMultiply(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test7_calculatorMultiply(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 26322.24; |
||||
|
num2 = 2332.222; |
||||
|
expected = num1 * num2; |
||||
|
actual = calculatorMultiply(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test8_calculatorMultiply(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 26132.24; |
||||
|
num2 = 2331122.222; |
||||
|
expected = num1 * num2; |
||||
|
actual = calculatorMultiply(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test9_calculatorMultiply(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 6322.24; |
||||
|
num2 = 21232.2322; |
||||
|
expected = num1 * num2; |
||||
|
actual = calculatorMultiply(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test10_calculatorMultiply(void) |
||||
|
{ |
||||
|
float num1, num2, actual ,expected; //Arrange |
||||
|
num1 = 1234.456; |
||||
|
num2 = 654.4321; |
||||
|
expected = num1 * num2; |
||||
|
actual = calculatorMultiply(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,121 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "../src/calculatorSubtract.c" |
||||
|
|
||||
|
// Note: |
||||
|
/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. |
||||
|
If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ |
||||
|
|
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void test1_calculatorSubtract(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 123.211; |
||||
|
num2 = 112.21; |
||||
|
expected = num1 - num2; |
||||
|
actual = calculatorSubtract(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test2_calculatorSubtract(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 13.21; |
||||
|
num2 = 112.21; |
||||
|
expected = num1 - num2; |
||||
|
actual = calculatorSubtract(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test3_calculatorSubtract(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 12231.211; |
||||
|
num2 = 1122.21; |
||||
|
expected = num1 - num2; |
||||
|
actual = calculatorSubtract(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test4_calculatorSubtract(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 113453.211; |
||||
|
num2 = 11254.21; |
||||
|
expected = num1 - num2; |
||||
|
actual = calculatorSubtract(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test5_calculatorSubtract(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 12133.211; |
||||
|
num2 = 112.231; |
||||
|
expected = num1 - num2; |
||||
|
actual = calculatorSubtract(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test6_calculatorSubtract(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 1133.201; |
||||
|
num2 = 11221.21; |
||||
|
expected = num1 - num2; |
||||
|
actual = calculatorSubtract(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test7_calculatorSubtract(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 12213.2211; |
||||
|
num2 = 111.21; |
||||
|
expected = num1 - num2; |
||||
|
actual = calculatorSubtract(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test8_calculatorSubtract(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 16213.711; |
||||
|
num2 = 1214.2251; |
||||
|
expected = num1 - num2; |
||||
|
actual = calculatorSubtract(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test9_calculatorSubtract(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 1933.611; |
||||
|
num2 = 1432.21; |
||||
|
expected = num1 - num2; |
||||
|
actual = calculatorSubtract(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
void test10_calculatorSubtract(void) |
||||
|
{ |
||||
|
float num1, num2, actual, expected; //Arrange |
||||
|
num1 = 1233.811; |
||||
|
num2 = 1121.131; |
||||
|
expected = num1 - num2; |
||||
|
actual = calculatorSubtract(num1, num2); //Act |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert |
||||
|
} |
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,57 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
#include "../src/checkLoanEligibility.c" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_checkLoanEligibilitySuccess(void) { |
||||
|
|
||||
|
/* Arrange */ |
||||
|
|
||||
|
int user_id[3] = {1234, 1327, 1666}; // user_ids from file for testing |
||||
|
|
||||
|
bool result[3]; |
||||
|
|
||||
|
/* Act */ |
||||
|
|
||||
|
for (int i = 0; i < 3; i++) { |
||||
|
result[i] = checkLoanEligibility(user_id[i]); |
||||
|
} |
||||
|
|
||||
|
/* Assert */ |
||||
|
|
||||
|
for (int i = 0; i < 3; i++) { |
||||
|
TEST_ASSERT_TRUE(result[i]); // Pass if user_id is found in the file |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void test_checkLoanEligibilityFailure(void) { |
||||
|
|
||||
|
/* Arrange */ |
||||
|
|
||||
|
int user_id[3] = {12314, 127, 166}; // Random wrong user_ids |
||||
|
|
||||
|
bool result[3]; |
||||
|
|
||||
|
/* Act */ |
||||
|
|
||||
|
for (int i = 0; i < 3; i++) { |
||||
|
result[i] = checkLoanEligibility(user_id[i]); |
||||
|
} |
||||
|
|
||||
|
/* Assert */ |
||||
|
|
||||
|
for (int i = 0; i < 3; i++) { |
||||
|
TEST_ASSERT_FALSE(result[i]); // Pass if the returned result is false |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,304 @@ |
|||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "../src/createEmployeeAccount.c" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_isValidEmployeeID(void) |
||||
|
{ |
||||
|
//test case 0 |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* validEmployeeId [] = {"Atharva","Can","Haytham","Julius","Mohamed","Shivam","Fizz","Buzz","JohnDoe","Foobar","waz","Objectoriented","INSTITUTIONALISATIOL","Intercommunicational","1234","1.6"}; |
||||
|
int validStringLengths = 20; |
||||
|
bool validEmployeeIdExpected = true; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i<15; i++) |
||||
|
{ |
||||
|
bool validEmployeeIdResult = isValidEmployeeID(validEmployeeId[i],validStringLengths); |
||||
|
TEST_ASSERT_EQUAL(validEmployeeIdExpected,validEmployeeIdResult); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void test_isNotValidEmployeeID(void) |
||||
|
{ |
||||
|
//test case 1 |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* invalidEmployeeId [] = {"Atha rva","Ca n","Geschwindigkeitsbegrenzungen","1234 15","John Doe","fizz Fuzz"}; |
||||
|
int invalidStringLengths = 20; |
||||
|
bool invalidEmployeeIdExpected = false; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i<6; i++) |
||||
|
{ |
||||
|
bool invalidEmployeeIdResult = isValidEmployeeID(invalidEmployeeId[i],invalidStringLengths); |
||||
|
TEST_ASSERT_EQUAL(invalidEmployeeIdExpected,invalidEmployeeIdResult); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_validEmployeePassword(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* validPassword [] = {"Atharva.123","02.September.2023","fdai7207.","array[20]","malloc(20*sizeof(int))","12.2E1234"}; |
||||
|
int minimalLength = 8; |
||||
|
bool validPasswordexpectation = true; |
||||
|
bool validPasswordResult[6]; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i<6; i++) |
||||
|
{ |
||||
|
validPasswordResult[i] = isValidPassword(validPassword[i],minimalLength); |
||||
|
TEST_ASSERT_EQUAL(validPasswordexpectation,validPasswordResult[i]); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_invalidEmployeePassword(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* invalidPassword [] = {"fizzbuzzio","02.09.2023",".^^_*+/-.","RTX4050ti","Can","github.com/bankmanagement-system"}; |
||||
|
int minimalLength = 8; |
||||
|
bool invalidPasswordexpected = false; |
||||
|
bool invalidPasswordResult[6]; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i<6; i++) |
||||
|
{ |
||||
|
invalidPasswordResult[i] = isValidPassword(invalidPassword[i],minimalLength); |
||||
|
TEST_ASSERT_EQUAL(invalidPasswordexpected,invalidPasswordResult[i]); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_verifyPasswordSuccess() |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* passwordsAndVerifications[][2] = { |
||||
|
{"Atharva123.","Atharva123."}, |
||||
|
{"fdai.7207","fdai.7207"}, |
||||
|
{"fizz.buzz132","fizz.buzz132"}, |
||||
|
{"23.March.1999","23.March.1999"}, |
||||
|
{"John.doe99","John.doe99"}, |
||||
|
{"foo/bar2","foo/bar2"}, |
||||
|
{"fizz+3buzz","fizz+3buzz"}, |
||||
|
{"gitlab2.com","gitlab2.com"}, |
||||
|
{"4test:all","4test:all"}, |
||||
|
{"WS-2023","WS-2023"} |
||||
|
}; |
||||
|
|
||||
|
bool expectation = true; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i<10; i++) |
||||
|
{ |
||||
|
bool result = verifyPassword(passwordsAndVerifications[i][0],passwordsAndVerifications[i][1]); |
||||
|
TEST_ASSERT_EQUAL(expectation,result); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void test_verifyPasswordFailure() |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* passwordsAndVerifications[][2] = { |
||||
|
{"Atharva123.","Atharva123"}, |
||||
|
{"fdai.7207","fdai.72"}, |
||||
|
{"fizz.buzz132","invalidPassword"}, |
||||
|
{"23.March.1999","23.May.1999"}, |
||||
|
{"John.doe99","Jane.doe99"}, |
||||
|
{"foo/bar2","foo*bar3"}, |
||||
|
{"fizz+3buzz","fizz-3buzz"}, |
||||
|
{"gitlab2.com","github.com"}, |
||||
|
{"4test:all","4ceedlingtest:all"}, |
||||
|
{"WS-2023","SS-2023"} |
||||
|
}; |
||||
|
|
||||
|
bool expectation = false; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i<10; i++) |
||||
|
{ |
||||
|
bool result = verifyPassword(passwordsAndVerifications[i][0],passwordsAndVerifications[i][1]); |
||||
|
TEST_ASSERT_EQUAL(expectation,result); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_employeesDataStoringSuccess(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
char* data[][4] ={ |
||||
|
{"John","Doe","fulda,leipzigerstr12","+4926428421469"}, |
||||
|
{"Jane","Done","fulda,leipzigerstr13","+4932517359874"}, |
||||
|
{"Foo","Bar","fulda,leipzigerstr14","+4913598765315"}, |
||||
|
{"Mustermann","Mustermanpass","fulda,leipzigerstr16","+4938197853812"} |
||||
|
}; |
||||
|
bool creationExpectation = true; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0;i<4;i++) |
||||
|
{ |
||||
|
bool creationResult = storeEmployeeData(data[i][0],data[i][1],data[i][2],data[i][3]); |
||||
|
TEST_ASSERT_EQUAL(creationExpectation,creationResult); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_employeeCreatedSuccessfully(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
char* potentialEmployees[][2] = { |
||||
|
{"John", "Doe"}, |
||||
|
{"Fizz", "Buzz"}, |
||||
|
{"Jane", "Doe"}, |
||||
|
{"Foo", "Bar"}, |
||||
|
{"MusterMann", "MusterManPassword"}, |
||||
|
{"MusterFrau", "MusterFrauPassword"} |
||||
|
}; |
||||
|
|
||||
|
bool expected = true; |
||||
|
bool result; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i<6;i++) |
||||
|
{ |
||||
|
result = createNewEmployee(potentialEmployees[i][0],potentialEmployees[i][1]); |
||||
|
TEST_ASSERT_EQUAL(expected,result); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_validName(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* validNames[] = {"John","Jane","Fizz","Fooo","Atharva","Cahn","Julius","Haytham","Mohamed","Shivam"}; |
||||
|
int minimalLength = 4; |
||||
|
bool validNamesExpectation = true; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i = 0;i<10;i++) |
||||
|
{ |
||||
|
bool validNamesResult = isValidName(validNames[i],minimalLength); |
||||
|
TEST_ASSERT_EQUAL(validNamesExpectation,validNamesResult); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_invalidName(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* invalidNames[] = {"Jo hn","Jane.","Fizz36","Foo8","Ath,arva","C .a1n","Jul.3ius","H613 aytham","Moh35gta.med","S-+h ivam"}; |
||||
|
int minimalLength = 4; |
||||
|
bool invalidNamesExpectation = false; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i = 0;i<10;i++) |
||||
|
{ |
||||
|
bool invalidNamesResult = isValidName(invalidNames[i],minimalLength); |
||||
|
TEST_ASSERT_EQUAL(invalidNamesExpectation,invalidNamesResult); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_validPhoneNumber(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
char* validPhoneNumbers[] = {"+4903584736198","+4912345678912","+4987541024534","+4932145784236","+4987264287139"}; |
||||
|
bool validPhoneNumbersExpectation = true; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
for(int i =0;i<5;i++) |
||||
|
{ |
||||
|
bool validPhoneNumbersResult = isValidPhoneNumber(validPhoneNumbers[i]); |
||||
|
TEST_ASSERT_EQUAL(validPhoneNumbersExpectation, validPhoneNumbersResult); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void test_isValidAdressSuccess(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
char* validCityAndStreet[][2] = { |
||||
|
{"LeipzigerStrasse","Hannover"}, |
||||
|
{"HannauerLandStra","Frankfurt"}, |
||||
|
{"HenirichStrasse","Berlin"}, |
||||
|
{"MAgdeburgerStrasse","Fulda"}}; |
||||
|
|
||||
|
int validHouseNumberAndPostalCode[][2] = { |
||||
|
{112,36879}, |
||||
|
{365,36897}, |
||||
|
{16,12354}, |
||||
|
{998,9999}}; |
||||
|
bool expectation = true; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
for(int i=0;i<4;i++) |
||||
|
{ |
||||
|
bool validAdress = isValidAdress(validCityAndStreet[i][0],validCityAndStreet[i][1],validHouseNumberAndPostalCode[i][0],validHouseNumberAndPostalCode[i][1]); |
||||
|
TEST_ASSERT_EQUAL(expectation,validAdress); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
void test_isValidAdressFailure(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
char* invalidCityAndStreet[][2] = { |
||||
|
{"LeipzigerStrassehvjhb","log"}, |
||||
|
{"HannauerLandStranl","fiz"}, |
||||
|
{"bob","foo"}, |
||||
|
{"..","bar"}}; |
||||
|
|
||||
|
int invalidHouseNumberAndPostalCode[][2] = { |
||||
|
{-10,-1}, |
||||
|
{-1,10}, |
||||
|
{0,999}, |
||||
|
{99815,65}}; |
||||
|
bool expectation = false; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
for(int i=0;i<4;i++) |
||||
|
{ |
||||
|
bool invalidAdress = isValidAdress(invalidCityAndStreet[i][0],invalidCityAndStreet[i][1],invalidHouseNumberAndPostalCode[i][0],invalidHouseNumberAndPostalCode[i][1]); |
||||
|
TEST_ASSERT_EQUAL(expectation,invalidAdress); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
void test_invalidPhoneNumber(void) |
||||
|
{ |
||||
|
/*Arrange*/ |
||||
|
char* invalidPhoneNumbers[] = {"+490358473619812","+6112345678912","+498754","-4932145784236","123"}; |
||||
|
bool invalidPhoneNumbersExpectation = false; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
for(int i =0;i<5;i++) |
||||
|
{ |
||||
|
bool invalidPhoneNumbersResult = isValidPhoneNumber(invalidPhoneNumbers[i]); |
||||
|
TEST_ASSERT_EQUAL(invalidPhoneNumbersExpectation,invalidPhoneNumbersResult); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,58 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
#include "../src/currencyExchange.c" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_convert(void) { |
||||
|
|
||||
|
/* Arrange */ |
||||
|
|
||||
|
int length = 10; |
||||
|
float euro[] = {34, 233, 400, 100, 45, 344, 767.32, 122, 435, 899}; |
||||
|
|
||||
|
float expectedUSD[length]; |
||||
|
float expectedGBP[length]; |
||||
|
float expectedYEN[length]; |
||||
|
float expectedYUAN[length]; |
||||
|
|
||||
|
float resultUSD[length]; |
||||
|
float resultGBP[length]; |
||||
|
float resultYEN[length]; |
||||
|
float resultYUAN[length]; |
||||
|
|
||||
|
for (int i = 0; i < length; i++) { |
||||
|
expectedUSD[i] = euro[i] * USD_RATE_OF_ONE_EURO; |
||||
|
expectedGBP[i] = euro[i] * GBP_RATE_OF_ONE_EURO; |
||||
|
expectedYEN[i] = euro[i] * JAPANESE_YEN_RATE_OF_ONE_EURO; |
||||
|
expectedYUAN[i] = euro[i] * CHINESE_YUAN_RATE_OF_ONE_EURO; |
||||
|
} |
||||
|
|
||||
|
/* Act */ |
||||
|
|
||||
|
for (int i = 0; i < length; i++) { |
||||
|
resultUSD[i] = convert(euro[i], CURRENCY_CODE_USD); |
||||
|
resultGBP[i] = convert(euro[i], CURRENCY_CODE_GBP); |
||||
|
resultYEN[i] = convert(euro[i], CURRENCY_CODE_JAPANESE_YEN); |
||||
|
resultYUAN[i] = convert(euro[i], CURRENCY_CODE_CHINESE_YUAN); |
||||
|
} |
||||
|
|
||||
|
/* Assert*/ |
||||
|
|
||||
|
for (int i = 0; i < length; i++) { |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedUSD[i], resultUSD[i]); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedGBP[i], resultGBP[i]); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedYEN[i], resultYEN[i]); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedYUAN[i], resultYUAN[i]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,87 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include <float.h> |
||||
|
#include "unity.h" |
||||
|
#include "../src/currentCustomerAccountBalance.c" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_fetchBalanceFromBalanceString(void) { |
||||
|
|
||||
|
/* Arrange */ |
||||
|
|
||||
|
char balanceString[5][100] = { |
||||
|
"balance=0", |
||||
|
"balance=100", |
||||
|
"balance=200", |
||||
|
"balance=300", |
||||
|
"balance=400" |
||||
|
}; |
||||
|
|
||||
|
/* Act */ |
||||
|
|
||||
|
float balance = 0; |
||||
|
float result[5]; |
||||
|
float expected[5]; |
||||
|
|
||||
|
for (int i = 0; i < 5; i++) { |
||||
|
result[i] = fetchBalanceFromBalanceString(balanceString[i]); |
||||
|
} |
||||
|
|
||||
|
/* Assert */ |
||||
|
|
||||
|
for (int i = 0; i < 5; i++) { |
||||
|
expected[i] = balance; |
||||
|
balance += 100; |
||||
|
} |
||||
|
|
||||
|
for (int i =0; i < 5; i++) { |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expected[i],result[i]); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
void test_checkFileOpen(void) { |
||||
|
|
||||
|
/* Act and assert */ |
||||
|
|
||||
|
FILE *file = fopen(CUSTOMER_DATA_FILE, "r"); |
||||
|
|
||||
|
TEST_ASSERT_TRUE(file); |
||||
|
|
||||
|
fclose(file); |
||||
|
} |
||||
|
|
||||
|
void test_failOpenFile(void) { |
||||
|
|
||||
|
/* Act and assert */ |
||||
|
|
||||
|
FILE *file = fopen("false_file_name", "r"); |
||||
|
|
||||
|
TEST_ASSERT_FALSE(file); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_getAvailableAccountBalance(void) { |
||||
|
|
||||
|
/* Act and assert */ |
||||
|
|
||||
|
int user_id = 1234; // Random user_id (because idea is to read the file and get a float value) |
||||
|
float max = FLT_MAX; |
||||
|
int result = getAvailableAccountBalance(user_id); |
||||
|
|
||||
|
TEST_ASSERT_TRUE(result < max); // Pass if function is successfully called and a float value (balance) is returned |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,36 @@ |
|||||
|
#include "unity.h" |
||||
|
#include "../src/currentCustomerAccountBalance.c" |
||||
|
#include "../src/depositMoney.c" |
||||
|
#include "../src/updateCustomerAccountBalance.c" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_depositSpecificAmount(void) { |
||||
|
|
||||
|
/* Arrange */ |
||||
|
|
||||
|
int length = 5; |
||||
|
int userIDs[] = {1234,1235,1236,1237,1238}; |
||||
|
float amountToDeposit[] = {200.5, 340, 244.5, 340, 1200}; |
||||
|
|
||||
|
bool result[length]; |
||||
|
|
||||
|
/* Act */ |
||||
|
|
||||
|
for (int i = 0; i < length; i++) { |
||||
|
result[i] = depositSpecificAmount( userIDs[i], amountToDeposit[i] ); |
||||
|
} |
||||
|
|
||||
|
/* Assert */ |
||||
|
|
||||
|
for (int i = 0; i < length; i++) { |
||||
|
TEST_ASSERT_TRUE(result[i]); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,31 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "../src/displayMenuCalculator.c" |
||||
|
#include "../src/calculatorAdd.c" |
||||
|
#include "../src/calculatorDivide.c" |
||||
|
#include "../src/calculatorFactorial.c" |
||||
|
#include "../src/calculatorGetUserInput.c" |
||||
|
#include "../src/calculatorGetUserInputFactorial.c" |
||||
|
#include "../src/calculatorMultiply.c" |
||||
|
#include "../src/calculatorSubtract.c" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_displayMenuCalculator(void) |
||||
|
{ |
||||
|
int expected, actual; //Arrange |
||||
|
expected = 1; |
||||
|
actual = check(); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual);//Assert |
||||
|
} |
||||
|
|
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,147 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "../src/employeeLogin.c" |
||||
|
#include "../src/showGeneralInfoEmployee.c" |
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_SuccessfulLoginEmployee_(void) |
||||
|
{ |
||||
|
|
||||
|
//test case : 0 |
||||
|
|
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* validEmployeesCredentials[][2] = { |
||||
|
{"Atharva", "Atharvafdai7514"}, |
||||
|
{"Can", "BlooMaskfdlt3817"}, |
||||
|
{"Haytham", "TimoDLfdai7207"}, |
||||
|
{"Julius", "Insertcatfdai7057"}, |
||||
|
{"Mohamed", "MDfdai6618"}, |
||||
|
{"Shivam", "Schivam007fdlt3781"} |
||||
|
}; |
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
int expected[] = {1,1,1,1,1,1}; |
||||
|
|
||||
|
for(int i=0; i<6; i++) |
||||
|
{ |
||||
|
|
||||
|
int result = checkEmployeeCredentials(validEmployeesCredentials[i][0], validEmployeesCredentials[i][1]); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT(expected[i],result); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_WrongInfosLoginEmployee(void) |
||||
|
{ |
||||
|
//test case : 1 |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* wrongEmployeesCredentials[][2] = { |
||||
|
{"Atharva", "doe"}, |
||||
|
{"Can", "Bar"}, |
||||
|
{"Haytham", "buzz"}, |
||||
|
{"Julius", "fizz"}, |
||||
|
{"Mohamed", "muster"}, |
||||
|
{"Shivam", "TimoDL"} |
||||
|
}; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
int expected[] = {2,2,2,2,2,2}; |
||||
|
|
||||
|
for(int i=0; i<6; i++) |
||||
|
{ |
||||
|
|
||||
|
int result = checkEmployeeCredentials(wrongEmployeesCredentials[i][0], wrongEmployeesCredentials[i][1]); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT(expected[i],result); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
void test_MissingLoginEmployee(void) |
||||
|
{ |
||||
|
|
||||
|
//test case : 2 |
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* missingEmployeesCredentials[][2] = { |
||||
|
{"Germany", "Berlin"}, |
||||
|
{"Italy", "Rome"}, |
||||
|
{"Belgium", "Bruxelle"}, |
||||
|
{"Swizerland", "Geneve"}, |
||||
|
{"Netherlands", "Amsterdam"}, |
||||
|
{"Sweden", "Stockholm"} |
||||
|
}; |
||||
|
|
||||
|
int expected[] = {0,0,0,0,0,0}; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i<6; i++) |
||||
|
{ |
||||
|
|
||||
|
int result = checkEmployeeCredentials(missingEmployeesCredentials[i][0], missingEmployeesCredentials[i][1]); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT(expected[i],result); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_validEmployeeAccessCode(void) |
||||
|
{ |
||||
|
//test case 0 |
||||
|
|
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char validAccesscode[11] = "DF9E9A8B5E"; |
||||
|
|
||||
|
/*Act*/ |
||||
|
bool validAccessCodeResult = employeesAccess(validAccesscode); |
||||
|
|
||||
|
/*Assert*/ |
||||
|
|
||||
|
TEST_ASSERT_TRUE(validAccessCodeResult); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_invalidEmployeeAccessCode(void) |
||||
|
{ |
||||
|
//test case 1 |
||||
|
|
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* invalidAccessCode[] = {"15","foo","fizz","buzz","fizzbuzz","test","bankmanagement"}; |
||||
|
bool invalidCodeExpectation = false; |
||||
|
|
||||
|
/*Act and assert*/ |
||||
|
|
||||
|
for(int i=0;i<7;i++) |
||||
|
{ |
||||
|
bool invalidCodeResults = employeesAccess(invalidAccessCode[i]); |
||||
|
TEST_ASSERT_EQUAL(invalidCodeExpectation,invalidCodeResults); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,213 @@ |
|||||
|
#include <stdlib.h> |
||||
|
#include <time.h> |
||||
|
#include <string.h> |
||||
|
#include <unity.h> |
||||
|
#include "../src/helperFunctions.c" |
||||
|
|
||||
|
void test_calculateStringLength() |
||||
|
{ |
||||
|
char *testStrings[] = {"linux","table","book","men","woman","boy","girl","computer","old","new","water","fire","bright","dark","black","white"}; int expectedResults[] = {5,5,4,3,5,3,4,8,3,3,5,4,6,4,5,5}; |
||||
|
int numberOfValues= sizeof(expectedResults) / sizeof(int); |
||||
|
for(int i=0;i<numberOfValues;++i){ |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResults[i], calculateStringLength(testStrings[i])); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void test_isLetterOfAlphabet() |
||||
|
{ |
||||
|
/*test block 1*/ |
||||
|
char *testStringsToTrue[] = {"adhj","kasdlwq","vbeuqor","kalkwyynmakj","kakswxl","akljlxjkcyxyklj","asdjhuwpwe","xbcvddd","klajksdjkl","ghghgtie","kajsd"}; |
||||
|
unsigned int numberOfElements = sizeof(testStringsToTrue) / sizeof(char *); |
||||
|
for(int i=0;i<numberOfElements;++i){ |
||||
|
TEST_ASSERT_TRUE(isLetterOfAlphabet(testStringsToTrue[i])); |
||||
|
} |
||||
|
/*test block 2*/ |
||||
|
char *testStringsToTrue_2[] = {"bcjyxhkjyxchjqwo","tree","garden","thinker","philosophy","linux","computer","lesson","teacher","table","drink","water","every", "Frank","city","economic","programming","task","smart","smarter","smartest","dumb","wood","animals","forest","display","hot","cold","ice","bear","keyboard","pair","pencil"}; |
||||
|
numberOfElements = sizeof(testStringsToTrue_2) / sizeof(char *); |
||||
|
for(int i=0;i<numberOfElements;++i){ |
||||
|
TEST_ASSERT_TRUE(isLetterOfAlphabet(testStringsToTrue_2[i])); |
||||
|
} |
||||
|
/*test block 3*/ |
||||
|
char *testStringsToFalse[] = {"ashjdkj32123","4213jashj","laskdj2","1sbabjsdh","askjasdkjd0","123932131a","abcd2hutz","81287asjk231jkhs","aslkjasdlkjsd123","cbc451873"}; |
||||
|
numberOfElements = sizeof(testStringsToFalse) / sizeof(char *); |
||||
|
for(int i=0;i<numberOfElements;++i){ |
||||
|
TEST_ASSERT_FALSE(isLetterOfAlphabet(testStringsToFalse[i])); |
||||
|
} |
||||
|
/*test block 4*/ |
||||
|
char *testStringsToFalse_2[] = {"1234","56789","00000010101010","3748927398273498","757575757","1726371238726","19237182937192837","875378612873621","128973192837","99494949499929292929292938382828","1827391237981273","7481263871236782136"}; |
||||
|
numberOfElements = sizeof(testStringsToFalse_2) / sizeof(char *); |
||||
|
for(int i=0;i<numberOfElements;++i){ |
||||
|
TEST_ASSERT_FALSE(isLetterOfAlphabet(testStringsToFalse_2[i])); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void test_toUnsignedInteger() |
||||
|
{ |
||||
|
/*test block 1*/ |
||||
|
char *strings[] = {"111","123","542","994","9000","8384","6473","12345","57837","78387","93276","1000","8444","48484"}; |
||||
|
int expected[] = {111,123,542,994,9000,8384,6473,12345,57837,78387,93276,1000,8444,48484}; |
||||
|
int length = sizeof(expected)/sizeof(int); |
||||
|
for(int i=0;i<length;++i){ |
||||
|
TEST_ASSERT_EQUAL_INT(expected[i], toUnsignedInteger(strings[i])); |
||||
|
} |
||||
|
|
||||
|
/*test block 2*/ |
||||
|
char *strings_2[] = {"9999","99999","9","99","999","0","19","10","90","8765"}; |
||||
|
int expected_2[] = {9999,99999,9,99,999,0,19,10,90,8765}; |
||||
|
length = sizeof(expected_2)/sizeof(int); |
||||
|
for(int i=0;i<length;++i){ |
||||
|
TEST_ASSERT_EQUAL_INT(expected_2[i], toUnsignedInteger(strings_2[i])); |
||||
|
} |
||||
|
|
||||
|
/*test block 3*/ |
||||
|
char *strings_3[] = {"0","1","1","2","3","5","8","13","21","34","55","89","144","233"}; |
||||
|
int expected_3[] = {0,1,1,2,3,5,8,13,21,34,55,89,144,233}; |
||||
|
length = sizeof(expected_3)/sizeof(int); |
||||
|
for(int i=0;i<length;++i){ |
||||
|
TEST_ASSERT_EQUAL_INT(expected_3[i], toUnsignedInteger(strings_3[i])); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
void test_everyCharacterIsDigit() |
||||
|
{ |
||||
|
/*test block 1*/ |
||||
|
char *expectTrue[] = {"0","11","222","3333","4444","134132","12352378","12847273","1237873","9992475","987232","34723873278","578347823783","758378723","44293884742", |
||||
|
"3184123872873","8912892383","18282828","55757575757528282","123823883282383282575757283832","99999999999999999999999999999999999","128321378","81293982139823","21412323" |
||||
|
"575757575754646464648383838383","1298557648298219821398129381928391283918238912831283928391283129839281391283918238912391238912839182391239857517828"}; |
||||
|
int length = sizeof(expectTrue)/sizeof(char *); |
||||
|
for(int i=0;i<length;++i){ |
||||
|
TEST_ASSERT_TRUE(everyCharacterIsDigit(expectTrue[i])); |
||||
|
} |
||||
|
|
||||
|
/*test block 2*/ |
||||
|
char *expectFalse[] = {"a","bcd","dhdd","3asad87","askj","nxbdj","489sjk2kj","kjasjkd38234","aksjlas","bcbc838ch","akjsjkdjkq919191","askjsdakj492","kasjcncn","9919a19","cbajsh","askjajkd","ajshdasjh","jyxhyxjchyx","kasjdakj","vbvb88888888888888828282828282828askjh"}; |
||||
|
length = sizeof(expectFalse)/sizeof(char *); |
||||
|
for(int i=0;i<length;++i){ |
||||
|
TEST_ASSERT_FALSE(everyCharacterIsDigit(expectFalse[i])); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void test_power() |
||||
|
{ |
||||
|
/*test block 1*/ |
||||
|
int testValues[] = {1,2,3,4,5,6,7,8,9,10}; |
||||
|
int expectedValues[] = {1,4,9,16,25,36,49,64,81,100}; |
||||
|
int length = sizeof(testValues)/sizeof(int); |
||||
|
const int exponent = 2; |
||||
|
for(int i=0;i<length;++i){ |
||||
|
TEST_ASSERT_EQUAL_INT(expectedValues[i], power(testValues[i],exponent)); |
||||
|
} |
||||
|
|
||||
|
/*test block 2*/ |
||||
|
int testValues_2[] = {11,12,13,14,15,16,17,18,19,20}; |
||||
|
int expectedValues_2[] = {121,144,169,196,225,256,289,324,361,400}; |
||||
|
length = sizeof(testValues_2)/sizeof(int); |
||||
|
for(int i=0;i<length;++i){ |
||||
|
TEST_ASSERT_EQUAL_INT(expectedValues_2[i],power(testValues_2[i],exponent)); |
||||
|
} |
||||
|
|
||||
|
/*test block 3*/ |
||||
|
int testValues_3[] = {1,2,3,4,5,6,7,8,9,10}; |
||||
|
int expectedValues_3[] = {1,8,27,64,125,216,343,512,729,1000}; |
||||
|
const int exponent_2 = 3; |
||||
|
length = sizeof(testValues_3)/sizeof(int); |
||||
|
for(int i=0;i<length;++i){ |
||||
|
TEST_ASSERT_EQUAL_INT(expectedValues_3[i],power(testValues_3[i],exponent_2)); |
||||
|
} |
||||
|
/*test block 4*/ |
||||
|
int testValues_4[] = {11,12,13,14,15,16,17,18,19,20}; |
||||
|
int expectedValues_4[] = {1331,1728,2197,2744,3375,4096,4913,5832,6859,8000}; |
||||
|
length = sizeof(testValues_4)/sizeof(int); |
||||
|
for(int i=0;i<length;++i){ |
||||
|
TEST_ASSERT_EQUAL_INT(expectedValues_4[i],power(testValues_4[i],exponent_2)); |
||||
|
} |
||||
|
/*test block 5*/ |
||||
|
int testValues_5[] = {0,0,19,2,4,5,11,54,32,12,77}; |
||||
|
int exponents[] = {0,1,2,7,4,2,0,1,2,4,2}; |
||||
|
int expectedValues_5[] = {0, 0, 361,128,256,25,1,54,1024,20736,5929}; |
||||
|
length = sizeof(testValues_5)/sizeof(int); |
||||
|
for(int i=0;i<length;++i){ |
||||
|
TEST_ASSERT_EQUAL_INT(expectedValues_5[i], power(testValues_5[i],exponents[i])); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void test_to_string() |
||||
|
{ |
||||
|
/*initializing test values*/ |
||||
|
char *result_1[] = {"0","1","2","3","4","5","6","7","8","9","10"}; |
||||
|
char *result_2[] = {"500","502","504","506","508","510","512","514","516","518"}; |
||||
|
char *result_3[] = {"1000","2000","3000","4000","5000","6000","7000","8000","9000","10000"}; |
||||
|
char *result_4[] = {"9999","8999","7999","6999","5999","4999","3999","2999","1999","999"}; |
||||
|
char *result_5[] = {"1000000","2000000","3000000","4000000","5000000","6000000","7000000", |
||||
|
"8000000","9000000","10000000"}; |
||||
|
|
||||
|
/*assertions*/ |
||||
|
for(int i=0;i<=10;++i){ |
||||
|
TEST_ASSERT_EQUAL_STRING(result_1[i],to_string(i)); |
||||
|
} |
||||
|
|
||||
|
for(int i=0, j=500;i<10;++i,j+=2){ |
||||
|
TEST_ASSERT_EQUAL_STRING(result_2[i],to_string(j)); |
||||
|
} |
||||
|
|
||||
|
for(int i=0, j=1000;i<10;++i,j+=1000){ |
||||
|
TEST_ASSERT_EQUAL_STRING(result_3[i],to_string(j)); |
||||
|
} |
||||
|
|
||||
|
for(int i=0, j=9999;i<10;++i,j-=1000){ |
||||
|
TEST_ASSERT_EQUAL_STRING(result_4[i], to_string(j)); |
||||
|
} |
||||
|
for(int i=0, j=1000000;i<10;++i,j+=1000000){ |
||||
|
TEST_ASSERT_EQUAL_STRING(result_5[i],to_string(j)); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
void test_generateCheckString() |
||||
|
{ |
||||
|
/*test block 1*/ |
||||
|
int numbers_1[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25}; |
||||
|
char *strings_1[] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}; |
||||
|
char *result_1[] = {"0=a","1=b","2=c","3=d","4=e","5=f","6=g","7=h","8=i","9=j","10=k","11=l","12=m","13=n","14=o","15=p","16=q","17=r", "18=s","19=t","20=u","21=v","22=w","23=x","24=y","25=z"}; |
||||
|
for(int i=0;i<26;++i){ |
||||
|
TEST_ASSERT_EQUAL_STRING(result_1[i],generateCheckString(numbers_1[i],*(strings_1+i))); |
||||
|
} |
||||
|
/*test block 2*/ |
||||
|
int numbers_2[] = {0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025}; |
||||
|
char *strings_2[] = {"z","zy","zyx","zyxw","zyxwv","zyxwvu","zyxwvut","zyxwvuts","zyxwvutsr","zyxwvutsrq","zyxwvutsrqp", |
||||
|
"zyxwvutsrqpo","zyxwvutsrqpon","zyxwvutsrqponm","zyxwvutsrqponml","zyxwvutsrqponmlk", |
||||
|
"zyxwvutsrqponmlkj","zyxwvutsrqponmlkji","zyxwvutsrqponmlkjih","zyxwvutsrqponmlkjihg","zyxwvutsrqponmlkjihgf", |
||||
|
"zyxwvutsrqponmlkjihgfe","zyxwvutsrqponmlkjihgfed","zyxwvutsrqponmlkjihgfedc","zyxwvutsrqponmlkjihgfedcb", |
||||
|
"zyxwvutsrqponmlkjihgfedcba"}; |
||||
|
char *result_2[] = {"0=z","1=zy","1=zyx","2=zyxw","3=zyxwv","5=zyxwvu","8=zyxwvut","13=zyxwvuts","21=zyxwvutsr","34=zyxwvutsrq", |
||||
|
"55=zyxwvutsrqp","89=zyxwvutsrqpo","144=zyxwvutsrqpon","233=zyxwvutsrqponm","377=zyxwvutsrqponml", |
||||
|
"610=zyxwvutsrqponmlk","987=zyxwvutsrqponmlkj","1597=zyxwvutsrqponmlkji","2584=zyxwvutsrqponmlkjih", |
||||
|
"4181=zyxwvutsrqponmlkjihg","6765=zyxwvutsrqponmlkjihgf","10946=zyxwvutsrqponmlkjihgfe", |
||||
|
"17711=zyxwvutsrqponmlkjihgfed","28657=zyxwvutsrqponmlkjihgfedc","46368=zyxwvutsrqponmlkjihgfedcb", |
||||
|
"75025=zyxwvutsrqponmlkjihgfedcba"}; |
||||
|
for(int i=0;i<26;++i){ |
||||
|
TEST_ASSERT_EQUAL_STRING(result_2[i],generateCheckString(numbers_2[i],*(strings_2+i))); |
||||
|
} |
||||
|
/*test block 3*/ |
||||
|
srand(time(0)); |
||||
|
int random_number=0; |
||||
|
char *random_numbers_strings[20]; |
||||
|
int random_numbers[20]; |
||||
|
for(int i=0;i<20;++i){ |
||||
|
random_number = (rand() % 100) + 1; |
||||
|
random_numbers_strings[i] = to_string(random_number); |
||||
|
random_numbers[i] = random_number; |
||||
|
} |
||||
|
char *strings_3[] = {"tree","plant","tea","programming","assembler","unix","BSD","snow","mountain","table","wood","forest", "calculator","book","light","keyboard","old","paper","pencil","voltage"}; |
||||
|
char *result_3[20]; |
||||
|
for(int i=0;i<20;++i){ |
||||
|
random_numbers_strings[i] = strcat(random_numbers_strings[i],"="); |
||||
|
result_3[i] = strcat(random_numbers_strings[i],strings_3[i]); |
||||
|
printf("%s\n",result_3[i]); |
||||
|
} |
||||
|
for(int i=0;i<20;++i){ |
||||
|
TEST_ASSERT_EQUAL_STRING(result_3[i],generateCheckString(random_numbers[i],strings_3[i])); |
||||
|
} |
||||
|
} |
@ -0,0 +1,50 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
#include "../src/interestCalculator.c" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_initiateInterest(void) { |
||||
|
|
||||
|
/* Arrange */ |
||||
|
|
||||
|
int length = 10; |
||||
|
float startAmount[] = {34, 233, 4400, 1600, 245, 34544, 3767.32, 1422, 5435, 8199}; |
||||
|
float yearlyInterest=12; |
||||
|
float durationInYears=2.5; |
||||
|
|
||||
|
float monthlyInterest=8; |
||||
|
float durationInMonths=3.9; |
||||
|
|
||||
|
float resultsYearly[length]; |
||||
|
float resultsMonthly[length]; |
||||
|
|
||||
|
float expectedYearly[]={44.2,302.9,5720,2080,318.5,44907.2,4897.516,1848.6,7065.5,10658.7}; |
||||
|
float expectedMonthly[]={44.608,305.696,5772.8,2099.2,321.44,45321.73,4942.724,1865.664,7130.72,10757.09}; |
||||
|
|
||||
|
/* Act */ |
||||
|
|
||||
|
for (int i = 0; i < length; i++) { |
||||
|
resultsYearly[i]=initiateInterest(startAmount[i],yearlyInterest/100, durationInYears); |
||||
|
} |
||||
|
for (int i = 0; i < length; i++) { |
||||
|
resultsMonthly[i]=initiateInterest(startAmount[i],monthlyInterest/100, durationInMonths); |
||||
|
} |
||||
|
|
||||
|
/* Assert*/ |
||||
|
|
||||
|
for (int i = 0; i < length; i++) { |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedYearly[i], resultsYearly[i]); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedMonthly[i], resultsMonthly[i]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,246 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "../src/mainMenu.c" |
||||
|
#include "../src/error.c" |
||||
|
#include "../src/loginCustomer.c" |
||||
|
#include "../src/helperFunctions.c" |
||||
|
#include "../src/createCustomer.c" |
||||
|
#include "../src/employeeLogin.c" |
||||
|
#include "../src/createEmployeeAccount.c" |
||||
|
#include "../src/customerMenu.c" |
||||
|
#include "../src/showGeneralInfoEmployee.c" |
||||
|
|
||||
|
#include "../src/calculatorAdd.c" |
||||
|
#include "../src/calculatorDivide.c" |
||||
|
#include "../src/calculatorFactorial.c" |
||||
|
#include "../src/calculatorGetUserInput.c" |
||||
|
#include "../src/calculatorGetUserInputFactorial.c" |
||||
|
#include "../src/calculatorMultiply.c" |
||||
|
#include "../src/calculatorSubtract.c" |
||||
|
#include "../src/displayMenuCalculator.c" |
||||
|
#include "../src/requestLoan.c" |
||||
|
|
||||
|
#include "../src/sendMoney.c" |
||||
|
#include "../src/withdrawMoney.c" |
||||
|
#include "../src/depositMoney.c" |
||||
|
#include "../src/currencyExchange.c" |
||||
|
#include "../src/updateCustomerAccountBalance.c" |
||||
|
#include "../src/currentCustomerAccountBalance.c" |
||||
|
|
||||
|
|
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_agePermissionValidAge(void) |
||||
|
{ |
||||
|
//Test case : 0 |
||||
|
|
||||
|
/*Arrange*/ |
||||
|
|
||||
|
int Age = 18; |
||||
|
|
||||
|
bool validAgeResult[83]; |
||||
|
|
||||
|
/*Act*/ |
||||
|
|
||||
|
for(int i =0; i < 83; i++){ |
||||
|
|
||||
|
validAgeResult[i]= agePermission(Age + 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]; |
||||
|
|
||||
|
|
||||
|
for(int i =-100; i < 18; i++) |
||||
|
{ |
||||
|
|
||||
|
invalidAge[i+100]= i; |
||||
|
} |
||||
|
|
||||
|
/*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) |
||||
|
{ |
||||
|
|
||||
|
//test case 0 |
||||
|
|
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* inputIsInteger[] = {"-10000000","-2000000","-354698","-66667","-7878","-987","-64","-5","0","1","2","10","201","333","4321","56974","698751","7878989","88954621" }; |
||||
|
|
||||
|
bool inputIsIntegerExpected = true; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i=0; i < 19; i++) |
||||
|
{ |
||||
|
bool inputIsIntegerResult = checkIfInteger(inputIsInteger[i]); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL(inputIsIntegerExpected,inputIsIntegerResult); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_IsNotInteger(void) |
||||
|
{ |
||||
|
//test case 1 |
||||
|
|
||||
|
/*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 inputIsNotIntegerExpected = false; |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
|
||||
|
for(int i=0; i<19; i++) |
||||
|
{ |
||||
|
bool inputIsNotIntegerResult = checkIfInteger(inputIsNotInteger[i]); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL(inputIsNotIntegerExpected,inputIsNotIntegerResult); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
void test_validChoiceInput(void) |
||||
|
{ |
||||
|
//test case 0 |
||||
|
|
||||
|
/*Arrange*/ |
||||
|
|
||||
|
int validInput[6]; |
||||
|
|
||||
|
bool validInputExpected = true; |
||||
|
|
||||
|
|
||||
|
|
||||
|
for(int i = 0; i < 6; i++) |
||||
|
{ |
||||
|
validInput[i] = i + 1; |
||||
|
} |
||||
|
|
||||
|
/*Act and Asssert*/ |
||||
|
|
||||
|
for(int i = 0; i < 6; i++) |
||||
|
{ |
||||
|
|
||||
|
bool validInputResult = chooseOption(validInput[i]); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL(validInputExpected,validInputResult); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_invalidChoiceInput_firstCase(void) |
||||
|
{ |
||||
|
// test case 1 |
||||
|
|
||||
|
/*Arrange*/ |
||||
|
|
||||
|
int invalidInput[100]; |
||||
|
|
||||
|
bool invalidInputExpected = false; |
||||
|
|
||||
|
|
||||
|
|
||||
|
for(int i = -100; i < 1; i++) |
||||
|
{ |
||||
|
invalidInput[i+100] = i; |
||||
|
} |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i = 0; i < 100; i++) |
||||
|
{ |
||||
|
|
||||
|
bool invalidInputResult = chooseOption(invalidInput[i]); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL(invalidInputExpected,invalidInputResult); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_invalidChoiceInput_secondCase(void) |
||||
|
{ |
||||
|
// test case 2 |
||||
|
|
||||
|
/*Arrange*/ |
||||
|
|
||||
|
int invalidInput[100]; |
||||
|
|
||||
|
bool invalidInputExpected = false; |
||||
|
|
||||
|
for(int i = 0; i < 100; i++) |
||||
|
{ |
||||
|
invalidInput[i] = i + 7; |
||||
|
} |
||||
|
|
||||
|
/*Act and Assert*/ |
||||
|
|
||||
|
for(int i = 0; i < 100; i++) |
||||
|
{ |
||||
|
bool invalidInputResult = chooseOption(invalidInput[i]); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL(invalidInputExpected,invalidInputResult); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,23 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "../src/requestLoan.c" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_requestLoan(void) |
||||
|
{ |
||||
|
int actual, expected; //Arrange |
||||
|
expected = 1; |
||||
|
actual = allow(); // Act |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); // Assert |
||||
|
} |
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,63 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "../src/showGeneralInfoEmployee.c" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void test1_showGeneralInfoEmployee(void) |
||||
|
{ |
||||
|
char employeeName[20] = "Atharva"; //Arrange |
||||
|
char password[20] = "Atharvafdai7514"; |
||||
|
int ergebnis = checkUser(employeeName, password); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(1, ergebnis); //Assert |
||||
|
} |
||||
|
void test2_showGeneralInfoEmployee(void) |
||||
|
{ |
||||
|
char employeeName[20] = "Can"; //Arrange |
||||
|
char password[20] = "BlooMaskfdlt3817"; |
||||
|
int ergebnis = checkUser(employeeName, password); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(2, ergebnis); //Assert |
||||
|
} |
||||
|
void test3_showGeneralInfoEmployee(void) |
||||
|
{ |
||||
|
char employeeName[20] = "Haytham"; //Arrange |
||||
|
char password[20] = "TimoDLfdai7207"; |
||||
|
int ergebnis = checkUser(employeeName, password); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(3, ergebnis); //Assert |
||||
|
} |
||||
|
void test4_showGeneralInfoEmployee(void) |
||||
|
{ |
||||
|
char employeeName[20] = "Julius"; //Arrange |
||||
|
char password[20] = "Insertcatfdai7057"; |
||||
|
int ergebnis = checkUser(employeeName, password); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(4, ergebnis); //Assert |
||||
|
} |
||||
|
void test5_showGeneralInfoEmployee(void) |
||||
|
{ |
||||
|
char employeeName[20] = "Mohamed"; //Arrange |
||||
|
char password[20] = "MDfdai6618"; |
||||
|
int ergebnis = checkUser(employeeName, password); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(5, ergebnis); //Assert |
||||
|
} |
||||
|
void test6_showGeneralInfoEmployee(void) |
||||
|
{ |
||||
|
char employeeName[20] = "Shivam"; //Arrange |
||||
|
char password[20] = "Schivam007fdlt3781"; |
||||
|
int ergebnis = checkUser(employeeName, password); //Act |
||||
|
TEST_ASSERT_EQUAL_INT(6, ergebnis); //Assert |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,67 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "../src/updateCustomerAccountBalance.c" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_updateAvailableAccountBalanceSuccess(void){ |
||||
|
|
||||
|
/* |
||||
|
int id1 = 1234; |
||||
|
int id2 = 1327; |
||||
|
int id3 = 1666; |
||||
|
|
||||
|
int newBalance1=500; |
||||
|
int newBalance2=800; |
||||
|
int newBalance3=700; |
||||
|
|
||||
|
bool results1=updateAvailableAccountBalance(id1,newBalance1); |
||||
|
bool results2=updateAvailableAccountBalance(id2,newBalance2); |
||||
|
bool results3=updateAvailableAccountBalance(id3,newBalance3); |
||||
|
|
||||
|
TEST_ASSERT_TRUE(results1); |
||||
|
TEST_ASSERT_TRUE(results2); |
||||
|
TEST_ASSERT_TRUE(results3); |
||||
|
*/ |
||||
|
|
||||
|
/* Arrange */ |
||||
|
|
||||
|
int length = 5; |
||||
|
|
||||
|
float amountToUpdate[] = {200.5, 340, 244.5, 340, 1200}; |
||||
|
int userIDs[] = {1234,1235,1236,1237,1238}; |
||||
|
|
||||
|
float expectedValue[length]; |
||||
|
bool result[length]; |
||||
|
|
||||
|
/* Act */ |
||||
|
|
||||
|
for (int i = 0; i < length; i++) { |
||||
|
result[i] = updateAvailableAccountBalance(userIDs[i],amountToUpdate[i]); |
||||
|
} |
||||
|
|
||||
|
/* Assert */ |
||||
|
|
||||
|
for (int i = 0; i < length; i++) { |
||||
|
TEST_ASSERT_TRUE(result[i]); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
void test_failOpenFile(void) { |
||||
|
|
||||
|
/* Act and assert */ |
||||
|
|
||||
|
FILE *file = fopen("false_file_name", "r"); |
||||
|
|
||||
|
TEST_ASSERT_FALSE(file); |
||||
|
|
||||
|
} |
||||
|
#endif |
@ -0,0 +1,93 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
#include "../src/withdrawMoney.c" |
||||
|
#include "../src/updateCustomerAccountBalance.c" |
||||
|
#include "../src/currentCustomerAccountBalance.c" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_initiateWithdraw(void) { |
||||
|
|
||||
|
/* Arrange */ |
||||
|
|
||||
|
int length = 10; |
||||
|
|
||||
|
float amountToWithdraw[] = {200.5, 340, 244.5, 340, 1200, 3232, 1123, 460.5, 900, 1005}; |
||||
|
float availableAccountBalance[] = {2000, 3400, 2445, 3400, 6000, 5000, 1000, 2000, 2000, 9000}; |
||||
|
|
||||
|
float expectedValue[length]; |
||||
|
float result[length]; |
||||
|
|
||||
|
/* Act */ |
||||
|
|
||||
|
for (int i = 0; i < length; i++) { |
||||
|
result[i] = initiateWithdraw( amountToWithdraw[i], availableAccountBalance[i] ); |
||||
|
} |
||||
|
|
||||
|
/* Assert */ |
||||
|
|
||||
|
for (int i = 0; i < length; i++) { |
||||
|
expectedValue[i] = ( availableAccountBalance[i] - amountToWithdraw[i] ); |
||||
|
} |
||||
|
|
||||
|
for (int i = 0; i < length; i++) { |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedValue[i],result[i]); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_withdrawSpecificAmountSuccess(void) { |
||||
|
|
||||
|
/* Arrange */ |
||||
|
|
||||
|
int user_id[3] = {1234, 1235, 1236}; // user_ids from file for testing |
||||
|
|
||||
|
bool result[3]; |
||||
|
|
||||
|
/* Act */ |
||||
|
|
||||
|
for (int i = 0; i < 3; i++) { |
||||
|
result[i] = withdrawSpecificAmount(user_id[i], 50); |
||||
|
} |
||||
|
|
||||
|
/* Assert */ |
||||
|
|
||||
|
for (int i = 0; i < 3; i++) { |
||||
|
TEST_ASSERT_TRUE(result[i]); // Pass if withdrawal is successful |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void test_withdrawSpecificAmountFailure(void) { |
||||
|
|
||||
|
/* Arrange */ |
||||
|
|
||||
|
int user_id[3] = {12934, 13027, 16606}; // Random wrong user_ids |
||||
|
|
||||
|
bool result[3]; |
||||
|
|
||||
|
/* Act */ |
||||
|
|
||||
|
for (int i = 0; i < 3; i++) { |
||||
|
result[i] = withdrawSpecificAmount(user_id[i], 50); |
||||
|
} |
||||
|
|
||||
|
/* Assert */ |
||||
|
|
||||
|
for (int i = 0; i < 3; i++) { |
||||
|
TEST_ASSERT_FALSE(result[i]); // Pass if withdrawal fails and function returns false |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
#endif // TEST |
Write
Preview
Loading…
Cancel
Save
Reference in new issue