Browse Source

Merge branch 'development' into 'feature/customer-creation'

# Conflicts:
#   src/mainMenu.c
remotes/origin/feature/customer-creation
fdai7057 2 years ago
parent
commit
6103f83bf8
  1. 73
      src/mainMenu.c
  2. 1
      src/mainMenu.h
  3. 47
      test/test_mainMenu.c

73
src/mainMenu.c

@ -24,16 +24,7 @@ bool checkIfInteger(char* userInput)
bool chooseOption(int choiceInput)
{
if(choiceInput<1 || choiceInput>4)
{
return false;
}
else
{
return true;
}
return !(choiceInput < 1 || choiceInput > 4);
}
@ -51,6 +42,8 @@ void ageInput()
while (true)
{
/*the userInput string is changed to a number with the strtol function*/
age = strtol(userInput,&userInputPointer,10);
if((checkIfInteger(userInput))&& (agePermission(age)))
@ -62,6 +55,8 @@ void ageInput()
menuInput();
menuInput();
break;
}
@ -89,56 +84,40 @@ void ageInput()
void menuInput()
{
char choiceInput[20];
char* choiceInputPointer;
int selection;
scanf("%s",choiceInput);
scanf("%s", choiceInput);
selection = strtol(choiceInput, &choiceInputPointer, 10);
while(true)
while (!checkIfInteger(choiceInput) || !chooseOption(selection))
{
selection = strtol(choiceInput,&choiceInputPointer,10);
if(chooseOption(selection) == true && checkIfInteger(choiceInput) == true)
{
switch(selection)
{
printf("Input invalid! try again!\n");
case 1 : printf("\nLoginAsCostumer() function will be implemented here soon\n\n");
scanf("%s", choiceInput);
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;
}
selection = strtol(choiceInput, &choiceInputPointer, 10);
}
switch(selection)
{
case 1 : printf("\nLoginAsCostumer() function will be implemented here soon\n\n");
break;
else
{
printf("Input invalid! try again!\n");
case 2 : printf("\ncreateCostumerAccount() function will be implemented here soon\n\n");
break;
scanf("%s",choiceInput);
}
}
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;
}
}
void showMenu()
{

1
src/mainMenu.h

@ -13,6 +13,7 @@ bool chooseOption(int choiceInput);
void ageInput();
void menuInput();
void showMenu();
void menuInput();
#endif

47
test/test_mainMenu.c

@ -134,25 +134,23 @@ void test_validChoiceInput(void)
int validInput[4];
bool validInputResult[4];
bool validInputExpected = true;
/*Act*/
for(int i = 0; i < 4; i++)
{
validInput[i] = i + 1;
}
/*Act and Asssert*/
for(int i = 0; i < 4; i++)
{
validInputResult[i] = chooseOption(validInput[i]);
}
/*Assert*/
bool validInputResult = chooseOption(validInput[i]);
for(int i = 0; i < 4; i++)
{
TEST_ASSERT_TRUE(validInputResult[i]);
TEST_ASSERT_EQUAL(validInputExpected,validInputResult);
}
}
@ -165,25 +163,24 @@ void test_invalidChoiceInput_firstCase(void)
int invalidInput[100];
bool invalidInputResult[100];
bool invalidInputExpected = false;
/*Act*/
for(int i = -100; i < 0; i++)
for(int i = -100; i < 1; i++)
{
invalidInput[i+100] = i;
}
/*Act and Assert*/
for(int i = 0; i < 100; i++)
{
invalidInputResult[i] = chooseOption(invalidInput[i]);
}
/*Assert*/
bool invalidInputResult = chooseOption(invalidInput[i]);
TEST_ASSERT_EQUAL(invalidInputExpected,invalidInputResult);
for(int i = 0; i < 100; i++)
{
TEST_ASSERT_FALSE(invalidInputResult[i]);
}
}
@ -196,27 +193,23 @@ void test_invalidChoiceInput_secondCase(void)
int invalidInput[100];
bool invalidInputResult[100];
/*Act*/
bool invalidInputExpected = false;
for(int i = 0; i < 100; i++)
{
invalidInput[i] = i + 5;
}
for(int i = 0; i < 100; i++)
{
invalidInputResult[i] = chooseOption(invalidInput[i]);
}
/*Assert*/
/*Act and Assert*/
for(int i = 0; i < 100; i++)
{
TEST_ASSERT_FALSE(invalidInputResult[i]);
bool invalidInputResult = chooseOption(invalidInput[i]);
TEST_ASSERT_EQUAL(invalidInputExpected,invalidInputResult);
}
}

Loading…
Cancel
Save