Browse Source

Merge branch 'feature/update-current-customer-account-balance' into feature/balance-operations

remotes/origin/feature/loan-eligibility
fdlt3817 2 years ago
parent
commit
70c31d464e
  1. 299
      build/test/cache/test_mainMenu.c
  2. 0
      build/test/dependencies/force_build
  3. 1
      build/test/dependencies/mainMenu.d
  4. 4
      build/test/dependencies/test_mainMenu.d
  5. 4
      build/test/dependencies/test_mainMenu_runner.d
  6. BIN
      build/test/out/c/mainMenu.o
  7. BIN
      build/test/out/c/test_mainMenu.o
  8. BIN
      build/test/out/c/test_mainMenu_runner.o
  9. BIN
      build/test/out/test_mainMenu.out
  10. 299
      build/test/preprocess/files/test_mainMenu.c
  11. 3
      build/test/preprocess/includes/test_mainMenu.c
  12. 30
      build/test/results/test_mainMenu.pass
  13. 0
      build/test/runners/test_mainMenu_runner.c
  14. 78
      src/updateCustomerAccountBalance.c
  15. 21
      tests/test_LoginCustomer.c
  16. 145
      tests/test_mainMenu.c

299
build/test/cache/test_mainMenu.c

@ -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
build/test/dependencies/force_build

1
build/test/dependencies/mainMenu.d

@ -0,0 +1 @@
build/test/out/c/mainMenu.o: src/mainMenu.c src/mainMenu.h

4
build/test/dependencies/test_mainMenu.d

@ -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

4
build/test/dependencies/test_mainMenu_runner.d

@ -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

BIN
build/test/out/c/mainMenu.o

BIN
build/test/out/c/test_mainMenu.o

BIN
build/test/out/c/test_mainMenu_runner.o

BIN
build/test/out/test_mainMenu.out

299
build/test/preprocess/files/test_mainMenu.c

@ -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);
}
}

3
build/test/preprocess/includes/test_mainMenu.c

@ -0,0 +1,3 @@
---
- "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h"
- src/mainMenu.h

30
build/test/results/test_mainMenu.pass

@ -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
build/test/runners/test_updateCustomerAccountBalance_runner.c → build/test/runners/test_mainMenu_runner.c

78
src/updateCustomerAccountBalance.c

@ -2,48 +2,25 @@
#include "currentCustomerAccountBalance.c" #include "currentCustomerAccountBalance.c"
#include "lineReplacer.h" #include "lineReplacer.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?");
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){ void replaceLineInFile(const char* file_name, int line, const char* new_line){
FILE* file = fopen(file_name, "r"); FILE* file = fopen(file_name, "r");
if (file == NULL) { if (file == NULL) {
troubleShoot(0);
printf("Error opening file!\n");
return; return;
} }
char current_string[100];
char current_string[1024];
int current_line = 1; int current_line = 1;
char *temp_file_name = calloc(8+1, sizeof(char));
temp_file_name = "src/temp.txt";
char *temp_file_name = "temp.txt";
FILE* temp_file = fopen(temp_file_name, "w"); FILE* temp_file = fopen(temp_file_name, "w");
if (temp_file == NULL) { if (temp_file == NULL) {
troubleShoot(1);
printf("Error creating temp file!\n");
fclose(file); fclose(file);
return; return;
} }
while (fgets(current_string, sizeof(current_string), file) != NULL) { while (fgets(current_string, sizeof(current_string), file) != NULL) {
if (current_line == line) { if (current_line == line) {
fprintf(temp_file, "%s\n", new_line);
//fputs("\n", temp_file);
fprintf(temp_file, "%s", new_line);
fputs("\n", temp_file);
} else { } else {
fprintf(temp_file, "%s", current_string); fprintf(temp_file, "%s", current_string);
} }
@ -52,38 +29,36 @@ void replaceLineInFile(const char* file_name, int line, const char* new_line){
fclose(file); fclose(file);
fclose(temp_file); fclose(temp_file);
if(remove(file_name)!=0){ if(remove(file_name)!=0){
troubleShoot(2);
printf("could not remove the original file!");
} // Remove the original file } // Remove the original file
if(rename(temp_file_name, file_name)!=0){ if(rename(temp_file_name, file_name)!=0){
troubleShoot(3);
printf("could not rename!");
} // Rename the temp file to the original file } // Rename the temp file to the original file
} }
void replaceBalanceInString(float replacementBalance, int currentLine) { void replaceBalanceInString(float replacementBalance, int currentLine) {
char newBalanceLine[MAX_LENGTH] = "balance="; char newBalanceLine[MAX_LENGTH] = "balance=";
char balance_as_string[MAX_LENGTH]; char balance_as_string[MAX_LENGTH];
sprintf(balance_as_string, "%f", replacementBalance); //converts replacement balance to string
sprintf(balance_as_string, "%g", replacementBalance); //converts replacement balance to string
strcat(newBalanceLine, balance_as_string); strcat(newBalanceLine, balance_as_string);
replaceLineInFile(CUSTOMER_DATA_FILE,currentLine,newBalanceLine);
replaceLineInFile("CustomerData.txt",currentLine,newBalanceLine);
} }
float updateAvailableAccountBalance(int user_id, float newBalance){
bool updateAvailableAccountBalance(int user_id, float newBalance){
bool keep_reading = true; bool keep_reading = true;
bool foundCustomer = false;
char *buffer = malloc(MAX_LENGTH * sizeof(char));
char *stringID = malloc(MAX_LENGTH * sizeof(char));
stringID = "ID=";
char *user_id_as_string =malloc(MAX_LENGTH * sizeof(char));
char *balance_String = malloc(MAX_LENGTH * sizeof(char));
char buffer[MAX_LENGTH];
char stringID[MAX_LENGTH] = "ID=";
char user_id_as_string[MAX_LENGTH];
char balance_String[MAX_LENGTH];
int currentLine=0; int currentLine=0;
sprintf(user_id_as_string, "%d", user_id); // converts user_id to string sprintf(user_id_as_string, "%d", user_id); // converts user_id to string
strcat(stringID, user_id_as_string); strcat(stringID, user_id_as_string);
FILE *file = fopen(CUSTOMER_DATA_FILE, "r");
//printf(stringID);
FILE *file = fopen("CustomerData.txt", "r+");
printf(stringID);
while(keep_reading) { while(keep_reading) {
fgets(buffer, MAX_LENGTH, file); fgets(buffer, MAX_LENGTH, file);
currentLine++; currentLine++;
@ -91,25 +66,16 @@ float updateAvailableAccountBalance(int user_id, float newBalance){
keep_reading = false; keep_reading = false;
} }
else if(strstr(buffer, stringID)) { //found the customer else if(strstr(buffer, stringID)) { //found the customer
for (int i = 0; i < 4; i++) {
fgets(buffer, MAX_LENGTH, file); fgets(buffer, MAX_LENGTH, file);
currentLine++;
}
fgets(buffer, MAX_LENGTH, file);
fgets(buffer, MAX_LENGTH, file);
fgets(buffer, MAX_LENGTH, file);
strcpy(balance_String, buffer); strcpy(balance_String, buffer);
currentLine+=4;
keep_reading = false; keep_reading = false;
foundCustomer=true;
} }
} }
fclose(file);
if(foundCustomer){
fclose(file);;
replaceBalanceInString(newBalance,currentLine); replaceBalanceInString(newBalance,currentLine);
return newBalance;
}else{
troubleShoot(4);
return -1;
}
} }

21
tests/test_LoginCustomer.c

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

145
tests/test_mainMenu.c

@ -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
Loading…
Cancel
Save