Browse Source

implement unit tests for the function chooseOption().

remotes/origin/beta
fdai7207 2 years ago
parent
commit
5a8d0bea89
  1. 2
      .gitignore
  2. 22
      src/mainMenu.c
  3. 1
      src/mainMenu.h
  4. 97
      tests/test_mainMenu.c

2
.gitignore

@ -0,0 +1,2 @@
.DS_Store
.swp

22
src/mainMenu.c

@ -1,7 +1,6 @@
#include "mainMenu.h" #include "mainMenu.h"
#include"createCustomer.c" #include"createCustomer.c"
bool agePermission(int age) bool agePermission(int age)
{ {
@ -21,6 +20,22 @@ bool checkIfInteger(char* userInput)
return !(endPointer == userInput || *endPointer != '\0'); return !(endPointer == userInput || *endPointer != '\0');
} }
bool chooseOption(int choiceInput)
{
if(choiceInput < 1 || choiceInput > 4)
{
return false;
}
else
{
return true;
}
}
void ageInput() void ageInput()
{ {
@ -63,10 +78,7 @@ void ageInput()
else else
{ {
printf("input invalid! try again!\n"); printf("input invalid! try again!\n");
fflush(stdin);
scanf("%s",userInput); scanf("%s",userInput);
fflush(stdin);
} }
@ -87,3 +99,5 @@ void showMenu()
printf("\n\n\n\n\n Selection :\n"); printf("\n\n\n\n\n Selection :\n");
} }

1
src/mainMenu.h

@ -8,6 +8,7 @@
bool agePermission(int age); bool agePermission(int age);
bool checkIfInteger(char* userInput); bool checkIfInteger(char* userInput);
bool chooseOption(int choiceInput);
void ageInput(); void ageInput();
void showMenu(); void showMenu();

97
tests/test_mainMenu.c

@ -126,4 +126,101 @@ void test_IsNotInteger(void)
} }
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 #endif // TEST
Loading…
Cancel
Save