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. 51
      src/mainMenu.c
  2. 1
      src/mainMenu.h
  3. 47
      test/test_mainMenu.c

51
src/mainMenu.c

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

1
src/mainMenu.h

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

47
test/test_mainMenu.c

@ -134,25 +134,23 @@ void test_validChoiceInput(void)
int validInput[4]; int validInput[4];
bool validInputResult[4];
bool validInputExpected = true;
/*Act*/
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
{ {
validInput[i] = i + 1; validInput[i] = i + 1;
} }
/*Act and Asssert*/
for(int i = 0; i < 4; i++) 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]; 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; invalidInput[i+100] = i;
} }
/*Act and Assert*/
for(int i = 0; i < 100; i++) 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]; int invalidInput[100];
bool invalidInputResult[100];
/*Act*/
bool invalidInputExpected = false;
for(int i = 0; i < 100; i++) for(int i = 0; i < 100; i++)
{ {
invalidInput[i] = i + 5; 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++) 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