Browse Source
Merge branch 'feature/update-current-customer-account-balance' into feature/deposit-system
remotes/origin/feature/deposit-system
Merge branch 'feature/update-current-customer-account-balance' into feature/deposit-system
remotes/origin/feature/deposit-system
fdlt3817
2 years ago
50 changed files with 1108 additions and 237 deletions
-
1.gitignore
-
6build-project.sh
-
3build/test/cache/defines_dependency.yml
-
20build/test/cache/input.yml
-
299build/test/cache/test_mainMenu.c
-
6build/test/dependencies/cmock.d
-
0build/test/dependencies/force_build
-
1build/test/dependencies/mainMenu.d
-
4build/test/dependencies/test_mainMenu.d
-
4build/test/dependencies/test_mainMenu_runner.d
-
4build/test/dependencies/unity.d
-
BINbuild/test/out/c/cmock.o
-
BINbuild/test/out/c/mainMenu.o
-
BINbuild/test/out/c/test_mainMenu.o
-
BINbuild/test/out/c/test_mainMenu_runner.o
-
BINbuild/test/out/c/unity.o
-
BINbuild/test/out/test_mainMenu.out
-
299build/test/preprocess/files/test_mainMenu.c
-
3build/test/preprocess/includes/test_mainMenu.c
-
30build/test/results/test_mainMenu.pass
-
12build/test/runners/test_mainMenu_runner.c
-
8project.yml
-
16src/CustomerData.txt
-
BINsrc/a.exe
-
50src/currentCustomerAccountBalance.c
-
7src/currentCustomerAccountBalance.h
-
6src/lineReplacer.h
-
93src/mainMenu.c
-
15src/mainMenu.h
-
83src/updateCustomerAccountBalance.c
-
11src/updateCustomerAccountBalance.h
-
3tests/build/test/cache/defines_dependency.yml
-
87tests/build/test/cache/test_LoginCustomer.c
-
3tests/build/test/dependencies/LoginCustomer.d
-
6tests/build/test/dependencies/cmock.d
-
4tests/build/test/dependencies/test_LoginCustomer.d
-
4tests/build/test/dependencies/test_LoginCustomer_runner.d
-
4tests/build/test/dependencies/unity.d
-
BINtests/build/test/out/c/LoginCustomer.o
-
BINtests/build/test/out/c/cmock.o
-
BINtests/build/test/out/c/test_LoginCustomer.o
-
BINtests/build/test/out/c/test_LoginCustomer_runner.o
-
BINtests/build/test/out/c/unity.o
-
BINtests/build/test/out/test_LoginCustomer.out
-
87tests/build/test/preprocess/files/test_LoginCustomer.c
-
3tests/build/test/preprocess/includes/test_LoginCustomer.c
-
18tests/build/test/results/test_LoginCustomer.pass
-
0tests/support/.gitkeep
-
0tests/test_LoginCustomer.c
-
145tests/test_mainMenu.c
@ -0,0 +1 @@ |
|||
.DS_Store |
@ -0,0 +1,6 @@ |
|||
clear |
|||
ceedling test:all |
|||
cd src/ |
|||
gcc main.c mainMenu.c |
|||
./a.out |
|||
rm a.out |
@ -0,0 +1,3 @@ |
|||
--- |
|||
src/mainMenu.c: |
|||
- TEST |
@ -0,0 +1,299 @@ |
|||
#include "src/mainMenu.h" |
|||
#include "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
void setUp(void) |
|||
|
|||
{ |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
void tearDown(void) |
|||
|
|||
{ |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
void test_agePermissionValidAge(void) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
int validAge[83]; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
_Bool |
|||
|
|||
validAgeResult[83]; |
|||
|
|||
|
|||
|
|||
int j=0; |
|||
|
|||
|
|||
|
|||
for(int i =18;i<101;i++){ |
|||
|
|||
|
|||
|
|||
validAge[j]= i; |
|||
|
|||
j++; |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<83;i++){ |
|||
|
|||
|
|||
|
|||
validAgeResult[i] = agePermission(validAge[i]); |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<83;i++){ |
|||
|
|||
|
|||
|
|||
do {if ((validAgeResult[i])) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(44)));}} while(0); |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
void test_agePermissionInvalidAge(void) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
int invalidAge[117]; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
_Bool |
|||
|
|||
invalidAgeResult[117]; |
|||
|
|||
|
|||
|
|||
int j=0; |
|||
|
|||
|
|||
|
|||
for(int i =-100;i<18;i++){ |
|||
|
|||
|
|||
|
|||
invalidAge[j]= i; |
|||
|
|||
j++; |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<117;i++){ |
|||
|
|||
|
|||
|
|||
invalidAgeResult[i] = agePermission(invalidAge[i]); |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<117;i++){ |
|||
|
|||
|
|||
|
|||
do {if (!(invalidAgeResult[i])) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(81)));}} while(0); |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
void test_IsInteger(void) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
char* inputIsInteger[] = {"-10000000","-2000000","-354698","-66667","-7878","-987","-64","-5","0","1","2","10","201","333","4321","56974","698751","7878989","88954621" }; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
_Bool |
|||
|
|||
inputIsIntegerResult[19]; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<19;i++) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
inputIsIntegerResult[i] = checkIfInteger(inputIsInteger[i]); |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<19;i++) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
do {if ((inputIsIntegerResult[i])) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(110)));}} while(0); |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
void test_IsNotInteger(void) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
char* inputIsNotInteger[] = {"0.15","3.141592653589793238","5.3254f","-6.264","-7878.3261","foo","Bar","FIZZ","buzZ","joHN","jAnE","foo-bar","3,15","2k13",""," ","-","+","/*-+.,/=" }; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
_Bool |
|||
|
|||
inputIsNotIntegerResult[19]; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<19;i++) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
inputIsNotIntegerResult[i] = checkIfInteger(inputIsNotInteger[i]); |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<19;i++) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
do {if (!(inputIsNotIntegerResult[i])) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(139)));}} while(0); |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,6 @@ |
|||
build/test/out/c/cmock.o: \ |
|||
/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock.c \ |
|||
/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock.h \ |
|||
/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock_internals.h \ |
|||
/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ |
|||
/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h |
@ -0,0 +1 @@ |
|||
build/test/out/c/mainMenu.o: src/mainMenu.c src/mainMenu.h |
@ -0,0 +1,4 @@ |
|||
build/test/out/c/test_mainMenu.o: tests/test_mainMenu.c \ |
|||
/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ |
|||
/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ |
|||
src/mainMenu.h |
@ -0,0 +1,4 @@ |
|||
build/test/out/c/test_mainMenu_runner.o: \ |
|||
build/test/runners/test_mainMenu_runner.c \ |
|||
/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ |
|||
/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h |
@ -0,0 +1,4 @@ |
|||
build/test/out/c/unity.o: \ |
|||
/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.c \ |
|||
/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ |
|||
/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h |
@ -0,0 +1,299 @@ |
|||
#include "src/mainMenu.h" |
|||
#include "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
void setUp(void) |
|||
|
|||
{ |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
void tearDown(void) |
|||
|
|||
{ |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
void test_agePermissionValidAge(void) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
int validAge[83]; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
_Bool |
|||
|
|||
validAgeResult[83]; |
|||
|
|||
|
|||
|
|||
int j=0; |
|||
|
|||
|
|||
|
|||
for(int i =18;i<101;i++){ |
|||
|
|||
|
|||
|
|||
validAge[j]= i; |
|||
|
|||
j++; |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<83;i++){ |
|||
|
|||
|
|||
|
|||
validAgeResult[i] = agePermission(validAge[i]); |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<83;i++){ |
|||
|
|||
|
|||
|
|||
do {if ((validAgeResult[i])) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(44)));}} while(0); |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
void test_agePermissionInvalidAge(void) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
int invalidAge[117]; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
_Bool |
|||
|
|||
invalidAgeResult[117]; |
|||
|
|||
|
|||
|
|||
int j=0; |
|||
|
|||
|
|||
|
|||
for(int i =-100;i<18;i++){ |
|||
|
|||
|
|||
|
|||
invalidAge[j]= i; |
|||
|
|||
j++; |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<117;i++){ |
|||
|
|||
|
|||
|
|||
invalidAgeResult[i] = agePermission(invalidAge[i]); |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<117;i++){ |
|||
|
|||
|
|||
|
|||
do {if (!(invalidAgeResult[i])) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(81)));}} while(0); |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
void test_IsInteger(void) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
char* inputIsInteger[] = {"-10000000","-2000000","-354698","-66667","-7878","-987","-64","-5","0","1","2","10","201","333","4321","56974","698751","7878989","88954621" }; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
_Bool |
|||
|
|||
inputIsIntegerResult[19]; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<19;i++) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
inputIsIntegerResult[i] = checkIfInteger(inputIsInteger[i]); |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<19;i++) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
do {if ((inputIsIntegerResult[i])) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(110)));}} while(0); |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
void test_IsNotInteger(void) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
char* inputIsNotInteger[] = {"0.15","3.141592653589793238","5.3254f","-6.264","-7878.3261","foo","Bar","FIZZ","buzZ","joHN","jAnE","foo-bar","3,15","2k13",""," ","-","+","/*-+.,/=" }; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
_Bool |
|||
|
|||
inputIsNotIntegerResult[19]; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<19;i++) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
inputIsNotIntegerResult[i] = checkIfInteger(inputIsNotInteger[i]); |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<19;i++) |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
do {if (!(inputIsNotIntegerResult[i])) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(139)));}} while(0); |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,3 @@ |
|||
--- |
|||
- "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" |
|||
- src/mainMenu.h |
@ -0,0 +1,30 @@ |
|||
--- |
|||
:source: |
|||
:path: tests |
|||
:file: test_mainMenu.c |
|||
:successes: |
|||
- :test: test_agePermissionValidAge |
|||
:line: 15 |
|||
:message: '' |
|||
:unity_test_time: 0 |
|||
- :test: test_agePermissionInvalidAge |
|||
:line: 50 |
|||
:message: '' |
|||
:unity_test_time: 0 |
|||
- :test: test_IsInteger |
|||
:line: 87 |
|||
:message: '' |
|||
:unity_test_time: 0 |
|||
- :test: test_IsNotInteger |
|||
:line: 116 |
|||
:message: '' |
|||
:unity_test_time: 0 |
|||
:failures: [] |
|||
:ignores: [] |
|||
:counts: |
|||
:total: 4 |
|||
:passed: 4 |
|||
:failed: 0 |
|||
:ignored: 0 |
|||
:stdout: [] |
|||
:time: 0.0009556771256029606 |
@ -0,0 +1,50 @@ |
|||
#include "currentCustomerAccountBalance.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 getAvailableAccountBalance(int user_id) { |
|||
bool keep_reading = true; |
|||
float availableBalance = 0; |
|||
|
|||
char buffer[MAX_LENGTH]; |
|||
char stringID[MAX_LENGTH] = "ID="; |
|||
char user_id_as_string[MAX_LENGTH]; |
|||
char balance_String[MAX_LENGTH]; |
|||
|
|||
sprintf(user_id_as_string, "%d", user_id); // converts user_id to string |
|||
strcat(stringID, user_id_as_string); |
|||
|
|||
FILE *file = fopen("CustomerData.txt", "r"); |
|||
|
|||
while(keep_reading) { |
|||
fgets(buffer, MAX_LENGTH, file); |
|||
if (feof(file)) { |
|||
keep_reading = false; |
|||
} |
|||
else if(strstr(buffer, stringID)) { |
|||
fgets(buffer, MAX_LENGTH, file); |
|||
fgets(buffer, MAX_LENGTH, file); |
|||
fgets(buffer, MAX_LENGTH, file); |
|||
fgets(buffer, MAX_LENGTH, file); |
|||
strcpy(balance_String, buffer); |
|||
availableBalance = fetchBalanceFromBalanceString(balance_String); |
|||
keep_reading = false; |
|||
} |
|||
|
|||
} |
|||
fclose(file); |
|||
|
|||
return availableBalance; |
|||
|
|||
} |
@ -0,0 +1,7 @@ |
|||
#include <stdio.h> |
|||
#include <stdbool.h> |
|||
#include <string.h> |
|||
#include <stdlib.h> |
|||
|
|||
#define MAX_LENGTH 100 |
|||
float getAvailableAccountBalance(int user_id); |
@ -0,0 +1,6 @@ |
|||
#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". |
@ -0,0 +1,93 @@ |
|||
|
|||
#include"mainMenu.h" |
|||
|
|||
|
|||
bool agePermission(int age){ |
|||
|
|||
if(age >= 18) |
|||
{ |
|||
|
|||
return true; |
|||
|
|||
} |
|||
|
|||
else |
|||
{ |
|||
|
|||
return false; |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
bool checkIfInteger(char* input){ |
|||
|
|||
char *end_pointer; |
|||
|
|||
strtol(input, &end_pointer, 10); |
|||
|
|||
if (end_pointer == input || *end_pointer != '\0') |
|||
{ |
|||
|
|||
return false; |
|||
|
|||
} |
|||
|
|||
else |
|||
{ |
|||
|
|||
return true; |
|||
|
|||
} |
|||
} |
|||
|
|||
void ageInput(){ |
|||
|
|||
char input[20]; |
|||
char* input_pointer; |
|||
|
|||
long age; |
|||
|
|||
printf("\nPlease specify your age : "); |
|||
scanf("%s",input); |
|||
|
|||
if (checkIfInteger(input) == true ) |
|||
{ |
|||
age = strtol(input,&input_pointer,10); |
|||
|
|||
if(agePermission(age)== true) |
|||
{ |
|||
printf("Access granted!\n\n\n\n"); |
|||
|
|||
showMenu(); |
|||
|
|||
} |
|||
else if(agePermission(age)== false) |
|||
{ |
|||
|
|||
printf("You should be at least 18 years old to create a bank account!\n"); |
|||
|
|||
} |
|||
} |
|||
|
|||
else |
|||
{ |
|||
|
|||
printf("input invalid! try again!\n"); |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
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\t\t ->Exit.\n"); |
|||
printf("\n\n\n\n\n Selection :\n"); |
|||
|
|||
} |
@ -0,0 +1,15 @@ |
|||
#ifndef MAINMENU_H_ |
|||
#define MAINMENU_H_ |
|||
|
|||
#include<stdio.h> |
|||
#include<stdlib.h> |
|||
#include<stdbool.h> |
|||
#include<string.h> |
|||
|
|||
void showMenu(); |
|||
void ageInput(); |
|||
|
|||
bool agePermission(int age); |
|||
bool checkIfInteger(char* input); |
|||
|
|||
#endif |
@ -0,0 +1,83 @@ |
|||
#include "updateCustomerAccountBalance.h" |
|||
#include "currentCustomerAccountBalance.c" |
|||
#include "lineReplacer.h" |
|||
|
|||
void replaceLineInFile(const char* file_name, int line, const char* new_line){ |
|||
FILE* file = fopen(file_name, "r"); |
|||
if (file == NULL) { |
|||
printf("Error opening file!\n"); |
|||
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) { |
|||
printf("Error creating temp file!\n"); |
|||
fclose(file); |
|||
return; |
|||
} |
|||
while (fgets(current_string, sizeof(current_string), file) != NULL) { |
|||
if (current_line == line) { |
|||
fprintf(temp_file, "%s", new_line); |
|||
} else { |
|||
fprintf(temp_file, "%s", current_string); |
|||
} |
|||
current_line++; |
|||
} |
|||
fclose(file); |
|||
fclose(temp_file); |
|||
if(remove(file_name)!=0){ |
|||
printf("could not remove the original file!"); |
|||
} // Remove the original file |
|||
if(rename(temp_file_name, file_name)!=0){ |
|||
printf("could not rename!"); |
|||
} // 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("CustomerData.txt",currentLine,newBalanceLine); |
|||
} |
|||
|
|||
bool updateAvailableAccountBalance(int user_id, float changeInBalance, bool positive){ |
|||
|
|||
bool keep_reading = true; |
|||
float availableBalance = 0; |
|||
|
|||
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("CustomerData.txt", "r+"); |
|||
printf(stringID); |
|||
while(keep_reading) { |
|||
fgets(buffer, MAX_LENGTH, file); |
|||
currentLine++; |
|||
if (feof(file)) { |
|||
keep_reading = false; |
|||
} |
|||
else if(strstr(buffer, stringID)) { //found the customer |
|||
fgets(buffer, MAX_LENGTH, file); |
|||
fgets(buffer, MAX_LENGTH, file); |
|||
fgets(buffer, MAX_LENGTH, file); |
|||
fgets(buffer, MAX_LENGTH, file); |
|||
strcpy(balance_String, buffer); |
|||
currentLine+=4; |
|||
availableBalance = fetchBalanceFromBalanceString(balance_String); |
|||
keep_reading = false; |
|||
} |
|||
|
|||
} |
|||
fclose(file); |
|||
float newBalance = (positive) ? availableBalance+changeInBalance : availableBalance-changeInBalance; |
|||
replaceBalanceInString(newBalance,currentLine); |
|||
} |
@ -0,0 +1,11 @@ |
|||
#include <stdio.h> |
|||
#include <stdbool.h> |
|||
#include <stdlib.h> |
|||
#include <string.h> |
|||
|
|||
#define MAX_LENGTH 100 |
|||
|
|||
|
|||
bool updateAvailableAccountBalance(int user_id, float changeInBalance, bool positive); |
|||
|
|||
void replaceBalanceInString(float replacementBalance, int currentLine); |
@ -1,3 +0,0 @@ |
|||
--- |
|||
"/home/julius/Documents/Studium/Informatik/1. Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/LoginCustomer.c": |
|||
- TEST |
@ -1,87 +0,0 @@ |
|||
#include "Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/LoginCustomer.h" |
|||
#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" |
|||
void setUp(){}; |
|||
|
|||
void tearDown(){}; |
|||
|
|||
void test_checkLogin() |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
_Bool |
|||
|
|||
expected_test_values_compute_to_true[] = {4==4, |
|||
|
|||
1 |
|||
|
|||
== |
|||
|
|||
1 |
|||
|
|||
, 1==1, |
|||
|
|||
0 |
|||
|
|||
== |
|||
|
|||
0 |
|||
|
|||
, '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, |
|||
|
|||
1 |
|||
|
|||
== |
|||
|
|||
0 |
|||
|
|||
,1==0, |
|||
|
|||
0 |
|||
|
|||
== |
|||
|
|||
1 |
|||
|
|||
,'z'=='x','!'==')',0x1A==0x2B}; |
|||
|
|||
int length_2 = sizeof(expected_test_values_compute_to_false)/sizeof( |
|||
|
|||
_Bool |
|||
|
|||
); |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<7;++i) { |
|||
|
|||
do {if ((checkLogin(expected_test_values_compute_to_true[i]))) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(16)));}} while(0); |
|||
|
|||
} |
|||
|
|||
for(int i=0;i<7;++i){ |
|||
|
|||
do {if (!(checkLogin(expected_test_values_compute_to_false[i]))) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(19)));}} while(0); |
|||
|
|||
} |
|||
|
|||
} |
@ -1,3 +0,0 @@ |
|||
build/test/out/c/LoginCustomer.o: \ |
|||
/home/julius/Documents/Studium/Informatik/1.\ Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/LoginCustomer.c \ |
|||
/home/julius/Documents/Studium/Informatik/1.\ Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/LoginCustomer.h |
@ -1,6 +0,0 @@ |
|||
build/test/out/c/cmock.o: \ |
|||
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock.c \ |
|||
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock.h \ |
|||
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock_internals.h \ |
|||
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ |
|||
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h |
@ -1,4 +0,0 @@ |
|||
build/test/out/c/test_LoginCustomer.o: test/test_LoginCustomer.c \ |
|||
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ |
|||
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ |
|||
/home/julius/Documents/Studium/Informatik/1.\ Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/LoginCustomer.h |
@ -1,4 +0,0 @@ |
|||
build/test/out/c/test_LoginCustomer_runner.o: \ |
|||
build/test/runners/test_LoginCustomer_runner.c \ |
|||
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ |
|||
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h |
@ -1,4 +0,0 @@ |
|||
build/test/out/c/unity.o: \ |
|||
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.c \ |
|||
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ |
|||
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h |
@ -1,87 +0,0 @@ |
|||
#include "Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/LoginCustomer.h" |
|||
#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" |
|||
void setUp(){}; |
|||
|
|||
void tearDown(){}; |
|||
|
|||
void test_checkLogin() |
|||
|
|||
{ |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
_Bool |
|||
|
|||
expected_test_values_compute_to_true[] = {4==4, |
|||
|
|||
1 |
|||
|
|||
== |
|||
|
|||
1 |
|||
|
|||
, 1==1, |
|||
|
|||
0 |
|||
|
|||
== |
|||
|
|||
0 |
|||
|
|||
, '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, |
|||
|
|||
1 |
|||
|
|||
== |
|||
|
|||
0 |
|||
|
|||
,1==0, |
|||
|
|||
0 |
|||
|
|||
== |
|||
|
|||
1 |
|||
|
|||
,'z'=='x','!'==')',0x1A==0x2B}; |
|||
|
|||
int length_2 = sizeof(expected_test_values_compute_to_false)/sizeof( |
|||
|
|||
_Bool |
|||
|
|||
); |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
for(int i=0;i<7;++i) { |
|||
|
|||
do {if ((checkLogin(expected_test_values_compute_to_true[i]))) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(16)));}} while(0); |
|||
|
|||
} |
|||
|
|||
for(int i=0;i<7;++i){ |
|||
|
|||
do {if (!(checkLogin(expected_test_values_compute_to_false[i]))) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(19)));}} while(0); |
|||
|
|||
} |
|||
|
|||
} |
@ -1,3 +0,0 @@ |
|||
--- |
|||
- "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" |
|||
- Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/LoginCustomer.h |
@ -1,18 +0,0 @@ |
|||
--- |
|||
:source: |
|||
:path: test |
|||
:file: test_LoginCustomer.c |
|||
:successes: |
|||
- :test: test_checkLogin |
|||
:line: 5 |
|||
:message: '' |
|||
:unity_test_time: 0 |
|||
:failures: [] |
|||
:ignores: [] |
|||
:counts: |
|||
:total: 1 |
|||
:passed: 1 |
|||
:failed: 0 |
|||
:ignored: 0 |
|||
:stdout: [] |
|||
:time: 0.001912861000164412 |
@ -0,0 +1,145 @@ |
|||
#ifdef TEST |
|||
|
|||
#include "unity.h" |
|||
|
|||
#include "mainMenu.h" |
|||
|
|||
void setUp(void) |
|||
{ |
|||
} |
|||
|
|||
void tearDown(void) |
|||
{ |
|||
} |
|||
|
|||
void test_agePermissionValidAge(void) |
|||
{ |
|||
//Test case : 0 |
|||
|
|||
//Arrange |
|||
|
|||
int validAge[83]; |
|||
|
|||
bool validAgeResult[83]; |
|||
|
|||
int j=0; |
|||
|
|||
for(int i =18;i<101;i++){ |
|||
|
|||
validAge[j]= i; |
|||
j++; |
|||
} |
|||
|
|||
//Act |
|||
|
|||
for(int i=0;i<83;i++){ |
|||
|
|||
validAgeResult[i] = agePermission(validAge[i]); |
|||
} |
|||
|
|||
//Assert |
|||
|
|||
for(int i=0;i<83;i++){ |
|||
|
|||
TEST_ASSERT_TRUE(validAgeResult[i]); |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
void test_agePermissionInvalidAge(void) |
|||
{ |
|||
|
|||
//Test case : 1 |
|||
|
|||
//Arrange |
|||
|
|||
int invalidAge[117]; |
|||
|
|||
bool invalidAgeResult[117]; |
|||
|
|||
int j=0; |
|||
|
|||
for(int i =-100;i<18;i++){ |
|||
|
|||
invalidAge[j]= i; |
|||
j++; |
|||
} |
|||
|
|||
//Act |
|||
|
|||
for(int i=0;i<117;i++){ |
|||
|
|||
invalidAgeResult[i] = agePermission(invalidAge[i]); |
|||
|
|||
} |
|||
|
|||
//Assert |
|||
|
|||
for(int i=0;i<117;i++){ |
|||
|
|||
TEST_ASSERT_FALSE(invalidAgeResult[i]); |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
void test_IsInteger(void) |
|||
{ |
|||
|
|||
//Arrange |
|||
|
|||
char* inputIsInteger[] = {"-10000000","-2000000","-354698","-66667","-7878","-987","-64","-5","0","1","2","10","201","333","4321","56974","698751","7878989","88954621" }; |
|||
|
|||
bool inputIsIntegerResult[19]; |
|||
|
|||
//Act |
|||
|
|||
for(int i=0;i<19;i++) |
|||
{ |
|||
|
|||
inputIsIntegerResult[i] = checkIfInteger(inputIsInteger[i]); |
|||
|
|||
} |
|||
|
|||
//Assert |
|||
|
|||
for(int i=0;i<19;i++) |
|||
{ |
|||
|
|||
TEST_ASSERT_TRUE(inputIsIntegerResult[i]); |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
void test_IsNotInteger(void) |
|||
{ |
|||
|
|||
//Arrange |
|||
|
|||
char* inputIsNotInteger[] = {"0.15","3.141592653589793238","5.3254f","-6.264","-7878.3261","foo","Bar","FIZZ","buzZ","joHN","jAnE","foo-bar","3,15","2k13",""," ","-","+","/*-+.,/=" }; |
|||
|
|||
bool inputIsNotIntegerResult[19]; |
|||
|
|||
//Act |
|||
|
|||
for(int i=0;i<19;i++) |
|||
{ |
|||
|
|||
inputIsNotIntegerResult[i] = checkIfInteger(inputIsNotInteger[i]); |
|||
|
|||
} |
|||
|
|||
//Assert |
|||
|
|||
for(int i=0;i<19;i++) |
|||
{ |
|||
|
|||
TEST_ASSERT_FALSE(inputIsNotIntegerResult[i]); |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
#endif // TEST |
Write
Preview
Loading…
Cancel
Save
Reference in new issue