Browse Source

Test arrangements

remotes/origin/feature/update-current-customer-account-balance
fdlt3817 2 years ago
parent
commit
cd78a96c03
  1. 2
      build/test/cache/defines_dependency.yml
  2. 12
      build/test/cache/input.yml
  3. 299
      build/test/cache/test_mainMenu.c
  4. 63
      build/test/cache/test_updateCustomerAccountBalance.c
  5. 10
      build/test/dependencies/cmock.d
  6. 0
      build/test/dependencies/force_build
  7. 1
      build/test/dependencies/mainMenu.d
  8. 4
      build/test/dependencies/test_mainMenu.d
  9. 4
      build/test/dependencies/test_mainMenu_runner.d
  10. 5
      build/test/dependencies/test_updateCustomerAccountBalance.d
  11. 4
      build/test/dependencies/test_updateCustomerAccountBalance_runner.d
  12. 6
      build/test/dependencies/unity.d
  13. 5
      build/test/dependencies/updateCustomerAccountBalance.d
  14. BIN
      build/test/out/c/cmock.o
  15. BIN
      build/test/out/c/mainMenu.o
  16. BIN
      build/test/out/c/test_mainMenu.o
  17. BIN
      build/test/out/c/test_mainMenu_runner.o
  18. BIN
      build/test/out/c/test_updateCustomerAccountBalance.o
  19. BIN
      build/test/out/c/test_updateCustomerAccountBalance_runner.o
  20. BIN
      build/test/out/c/unity.o
  21. BIN
      build/test/out/c/updateCustomerAccountBalance.o
  22. BIN
      build/test/out/test_mainMenu.out
  23. BIN
      build/test/out/test_updateCustomerAccountBalance.out
  24. 299
      build/test/preprocess/files/test_mainMenu.c
  25. 63
      build/test/preprocess/files/test_updateCustomerAccountBalance.c
  26. 3
      build/test/preprocess/includes/test_mainMenu.c
  27. 3
      build/test/preprocess/includes/test_updateCustomerAccountBalance.c
  28. 30
      build/test/results/test_mainMenu.pass
  29. 12
      build/test/runners/test_updateCustomerAccountBalance_runner.c
  30. 27
      src/updateCustomerAccountBalance.c
  31. 21
      tests/test_LoginCustomer.c
  32. 145
      tests/test_mainMenu.c
  33. 34
      tests/test_updateCustomerAccountBalance.c

2
build/test/cache/defines_dependency.yml

@ -1,3 +1,3 @@
--- ---
src/mainMenu.c:
src/updateCustomerAccountBalance.c:
- TEST - TEST

12
build/test/cache/input.yml

@ -77,10 +77,10 @@
:testfail: ".fail" :testfail: ".fail"
:dependencies: ".d" :dependencies: ".d"
:unity: :unity:
:vendor_path: "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor"
:vendor_path: "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor"
:defines: [] :defines: []
:cmock: :cmock:
:vendor_path: "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor"
:vendor_path: "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor"
:defines: [] :defines: []
:includes: [] :includes: []
:mock_prefix: mock_ :mock_prefix: mock_
@ -99,7 +99,7 @@
:verbosity: 3 :verbosity: 3
:unity_helper: false :unity_helper: false
:cexception: :cexception:
:vendor_path: "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/vendor"
:vendor_path: "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor"
:defines: [] :defines: []
:test_runner: :test_runner:
:includes: [] :includes: []
@ -223,13 +223,13 @@
:arguments: [] :arguments: []
:plugins: :plugins:
:load_paths: :load_paths:
- "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/lib/../plugins"
- "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/lib/../plugins"
:enabled: :enabled:
- stdout_pretty_tests_report - stdout_pretty_tests_report
- module_generator - module_generator
:display_raw_test_results: false :display_raw_test_results: false
:stdout_pretty_tests_report_path: "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/lib/../plugins/stdout_pretty_tests_report"
:module_generator_path: "/var/lib/gems/3.0.0/gems/ceedling-0.31.1/lib/../plugins/module_generator"
:stdout_pretty_tests_report_path: "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/lib/../plugins/stdout_pretty_tests_report"
:module_generator_path: "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/lib/../plugins/module_generator"
:gcov: :gcov:
:reports: :reports:
- HtmlDetailed - HtmlDetailed

299
build/test/cache/test_mainMenu.c

@ -1,299 +0,0 @@
#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);
}
}

63
build/test/cache/test_updateCustomerAccountBalance.c

@ -0,0 +1,63 @@
#include "src/updateCustomerAccountBalance.h"
#include "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h"
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);
do {if ((results1)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(29)));}} while(0);
do {if ((results2)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(30)));}} while(0);
do {if ((results3)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(31)));}} while(0);
}

10
build/test/dependencies/cmock.d

@ -1,6 +1,6 @@
build/test/out/c/cmock.o: \ 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
/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock.c \
/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock.h \
/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/cmock/src/cmock_internals.h \
/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \
/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h

0
build/test/dependencies/force_build

1
build/test/dependencies/mainMenu.d

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

4
build/test/dependencies/test_mainMenu.d

@ -1,4 +0,0 @@
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

@ -1,4 +0,0 @@
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

5
build/test/dependencies/test_updateCustomerAccountBalance.d

@ -0,0 +1,5 @@
build/test/out/c/test_updateCustomerAccountBalance.o: \
tests/test_updateCustomerAccountBalance.c \
/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \
/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \
src/updateCustomerAccountBalance.h

4
build/test/dependencies/test_updateCustomerAccountBalance_runner.d

@ -0,0 +1,4 @@
build/test/out/c/test_updateCustomerAccountBalance_runner.o: \
build/test/runners/test_updateCustomerAccountBalance_runner.c \
/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \
/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h

6
build/test/dependencies/unity.d

@ -1,4 +1,4 @@
build/test/out/c/unity.o: \ 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
/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.c \
/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \
/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h

5
build/test/dependencies/updateCustomerAccountBalance.d

@ -0,0 +1,5 @@
build/test/out/c/updateCustomerAccountBalance.o: \
src/updateCustomerAccountBalance.c src/updateCustomerAccountBalance.h \
src/currentCustomerAccountBalance.c \
src/currentCustomerAccountBalance.h src/_file_information.h \
src/lineReplacer.h

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

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/c/test_updateCustomerAccountBalance.o

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

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

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

BIN
build/test/out/test_mainMenu.out

BIN
build/test/out/test_updateCustomerAccountBalance.out

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

@ -1,299 +0,0 @@
#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);
}
}

63
build/test/preprocess/files/test_updateCustomerAccountBalance.c

@ -0,0 +1,63 @@
#include "src/updateCustomerAccountBalance.h"
#include "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h"
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);
do {if ((results1)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(29)));}} while(0);
do {if ((results2)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(30)));}} while(0);
do {if ((results3)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(31)));}} while(0);
}

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

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

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

@ -0,0 +1,3 @@
---
- "/Users/canhacioglu/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h"
- src/updateCustomerAccountBalance.h

30
build/test/results/test_mainMenu.pass

@ -1,30 +0,0 @@
---
: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

12
build/test/runners/test_mainMenu_runner.c → build/test/runners/test_updateCustomerAccountBalance_runner.c

@ -10,10 +10,7 @@ char* GlobalOrderError;
/*=======External Functions This Runner Calls=====*/ /*=======External Functions This Runner Calls=====*/
extern void setUp(void); extern void setUp(void);
extern void tearDown(void); extern void tearDown(void);
extern void test_agePermissionValidAge(void);
extern void test_agePermissionInvalidAge(void);
extern void test_IsInteger(void);
extern void test_IsNotInteger(void);
extern void test_updateAvailableAccountBalanceSuccess(void);
/*=======Mock Management=====*/ /*=======Mock Management=====*/
@ -77,11 +74,8 @@ static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE l
/*=======MAIN=====*/ /*=======MAIN=====*/
int main(void) int main(void)
{ {
UnityBegin("test_mainMenu.c");
run_test(test_agePermissionValidAge, "test_agePermissionValidAge", 15);
run_test(test_agePermissionInvalidAge, "test_agePermissionInvalidAge", 50);
run_test(test_IsInteger, "test_IsInteger", 87);
run_test(test_IsNotInteger, "test_IsNotInteger", 116);
UnityBegin("test_updateCustomerAccountBalance.c");
run_test(test_updateAvailableAccountBalanceSuccess, "test_updateAvailableAccountBalanceSuccess", 15);
return UnityEnd(); return UnityEnd();
} }

27
src/updateCustomerAccountBalance.c

@ -8,19 +8,20 @@ void replaceLineInFile(const char* file_name, int line, const char* new_line){
printf("Error opening file!\n"); printf("Error opening file!\n");
return; return;
} }
char current_string[1024];
char current_string[100];
int current_line = 1; int current_line = 1;
char *temp_file_name = "temp.txt";
char *temp_file_name = calloc(8+1, sizeof(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) {
printf("Error creating temp file!\n"); 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", new_line);
fputs("\n", temp_file);
fprintf(temp_file, "%s\n", new_line);
//fputs("\n", temp_file);
} else { } else {
fprintf(temp_file, "%s", current_string); fprintf(temp_file, "%s", current_string);
} }
@ -39,7 +40,7 @@ void replaceLineInFile(const char* file_name, int line, const char* new_line){
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, "%g", replacementBalance); //converts replacement balance to string
sprintf(balance_as_string, "%f", replacementBalance); //converts replacement balance to string
strcat(newBalanceLine, balance_as_string); strcat(newBalanceLine, balance_as_string);
replaceLineInFile("CustomerData.txt",currentLine,newBalanceLine); replaceLineInFile("CustomerData.txt",currentLine,newBalanceLine);
} }
@ -48,17 +49,18 @@ bool updateAvailableAccountBalance(int user_id, float newBalance){
bool keep_reading = true; bool keep_reading = true;
char buffer[MAX_LENGTH];
char stringID[MAX_LENGTH] = "ID=";
char user_id_as_string[MAX_LENGTH];
char balance_String[MAX_LENGTH];
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));
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("CustomerData.txt", "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++;
@ -78,4 +80,5 @@ bool updateAvailableAccountBalance(int user_id, float newBalance){
} }
fclose(file);; fclose(file);;
replaceBalanceInString(newBalance,currentLine); replaceBalanceInString(newBalance,currentLine);
return true;
} }

21
tests/test_LoginCustomer.c

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

145
tests/test_mainMenu.c

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

34
tests/test_updateCustomerAccountBalance.c

@ -0,0 +1,34 @@
#ifdef TEST
#include "unity.h"
#include "updateCustomerAccountBalance.h"
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);
}
#endif
Loading…
Cancel
Save