diff --git a/build-project.sh b/build-project.sh index 43a0588..ea712c3 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,5 +1,6 @@ clear +ceedling test:all cd src/ -gcc main.c -o main +gcc -o main main.c mainMenu.c ./main rm main diff --git a/project.yml b/project.yml new file mode 100644 index 0000000..e253248 --- /dev/null +++ b/project.yml @@ -0,0 +1,101 @@ +--- + +# 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: + - +:test/** + - -:test/support + :source: + - src/** + :support: + - test/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 +... diff --git a/src/main.c b/src/main.c index a3a8e04..b37734e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,8 @@ -#include -int main(){ -return 0; +#include "mainMenu.h" + +int main() { + + ageInput(); + + return 0; } diff --git a/src/mainMenu.c b/src/mainMenu.c new file mode 100644 index 0000000..bed41d9 --- /dev/null +++ b/src/mainMenu.c @@ -0,0 +1,154 @@ +#include"mainMenu.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) +{ + + if(choiceInput<1 || choiceInput>4) + { + return false; + } + + else + { + + return true; + } + +} + +void ageInput() +{ + + char* userInput = malloc(20*sizeof(char*)); + char* userInputPointer; + + long age; + + printf("\nPlease specify your age : "); + scanf("%s",userInput); + + + while (true) + { + 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))) + { + + printf("You should be at least 18 years old to create a bank account!\n"); + + break; + + } + + else + { + printf("input invalid! try again!\n"); + + scanf("%s",userInput); + + } + + } + +} + +void menuInput() +{ + + char choiceInput[20]; + + char* choiceInputPointer; + + int selection; + + scanf("%s",choiceInput); + + while(true) + { + selection = strtol(choiceInput,&choiceInputPointer,10); + + if(chooseOption(selection) == true && checkIfInteger(choiceInput) == true) + { + switch(selection) + { + + case 1 : printf("\nLoginAsCostumer() function will be implemented here soon\n\n"); + + break; + + case 2 : printf("\ncreateCostumerAccount() function will be implemented here soon\n\n"); + + break; + + case 3 : printf("\nLoginAsEmployee() function will be implemented here soon\n\n"); + + break; + + case 4 : printf("\e[1;1H\e[2J"); + + printf("\nsee you next time !\n\n"); + + break; + + } + break; + } + + else + { + printf("Input invalid! try again!\n"); + + scanf("%s",choiceInput); + } + } + +} + +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"); + +} + diff --git a/src/mainMenu.h b/src/mainMenu.h new file mode 100644 index 0000000..1be573f --- /dev/null +++ b/src/mainMenu.h @@ -0,0 +1,18 @@ +#ifndef MAINMENU_H_ +#define MAINMENU_H_ + +#include +#include +#include +#include + +bool agePermission(int age); +bool checkIfInteger(char* userInput); +bool chooseOption(int choiceInput); + +void ageInput(); +void menuInput(); +void showMenu(); + +#endif + diff --git a/team.md b/team.md index 02580e9..f0e0a28 100644 --- a/team.md +++ b/team.md @@ -1,9 +1,6 @@ -# Bankmanagement-System - -- Can Hacioglu, Fdlt3817 +- Can Hacioglu, fdlt3817 - Atharva Kishor Naik, fdai7514 - Julius Philipp Engel, fdai7057 - Shivam Chaudhary, fdlt3781 - Mohamed Yahya Dahi, fdai6618 -- Haytham Daoula, fdai7207 - +- Haytham Daoula, fdai7207 \ No newline at end of file diff --git a/test/support/.gitkeep b/test/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/test_mainMenu.c b/test/test_mainMenu.c new file mode 100644 index 0000000..ea65cc2 --- /dev/null +++ b/test/test_mainMenu.c @@ -0,0 +1,226 @@ +#ifdef TEST + +#include "unity.h" + +#include "mainMenu.h" + +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]= 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[4]; + + bool validInputResult[4]; + + /*Act*/ + + for(int i = 0; i < 4; i++) + { + validInput[i] = i + 1; + } + + for(int i = 0; i < 4; i++) + { + validInputResult[i] = chooseOption(validInput[i]); + } + + /*Assert*/ + + for(int i = 0; i < 4; i++) + { + TEST_ASSERT_TRUE(validInputResult[i]); + } + +} + +void test_invalidChoiceInput_firstCase(void) +{ + // test case 1 + + /*Arrange*/ + + int invalidInput[100]; + + bool invalidInputResult[100]; + + /*Act*/ + + for(int i = -100; i < 0; i++) + { + invalidInput[i+100] = i; + } + + for(int i = 0; i < 100; i++) + { + invalidInputResult[i] = chooseOption(invalidInput[i]); + } + + /*Assert*/ + + for(int i = 0; i < 100; i++) + { + TEST_ASSERT_FALSE(invalidInputResult[i]); + } + +} + +void test_invalidChoiceInput_secondCase(void) +{ + // test case 2 + + /*Arrange*/ + + int invalidInput[100]; + + bool invalidInputResult[100]; + + /*Act*/ + + for(int i = 0; i < 100; i++) + { + invalidInput[i] = i + 5; + } + + for(int i = 0; i < 100; i++) + { + invalidInputResult[i] = chooseOption(invalidInput[i]); + } + + /*Assert*/ + + for(int i = 0; i < 100; i++) + { + TEST_ASSERT_FALSE(invalidInputResult[i]); + } + +} + + + + + +#endif // TEST