Browse Source

implement unit tests for the function validPhoneNumber().

remotes/origin/feature/employees-infos-access
fdai7207 2 years ago
parent
commit
57292f4b64
  1. 19
      src/createEmployeeAccount.c
  2. 1
      src/createEmployeeAccount.h
  3. 2
      src/mainMenu.c
  4. 38
      tests/test_createEmployeeAccount.c

19
src/createEmployeeAccount.c

@ -67,6 +67,25 @@ bool isValidName(char* name,const int minimalLength)
return true;
}
bool isValidPhoneNumber(char *phoneNumber)
{
const int validNumberLength = 14;
int numberLength = strlen(phoneNumber);
if(numberLength != validNumberLength)
{
return false;
}
if(phoneNumber[0]!='+' || phoneNumber[1]!='4' || phoneNumber[2]!='9')
{
return false;
}
return true;
}
int StringLengthCounter(char* string)
{
int characterCounter = 0;

1
src/createEmployeeAccount.h

@ -26,6 +26,7 @@ bool createNewEmployee(char* employeeId, char* employeePassword);
bool verifyPassword(char* enteredPassword,char* passwordConfirmation);
bool storeEmployeeData(const char *name,const char *lastName,const char *adress,const char *phoneNumber);
bool isValidName(char* name,int minimalLength);
bool isValidPhoneNumber(char *phoneNumber);
int StringLengthCounter(char* string);

2
src/mainMenu.c

@ -80,7 +80,7 @@ void ageInput()
}
}
}
}
void menuInput()

38
tests/test_createEmployeeAccount.c

@ -226,4 +226,42 @@ void test_invalidName(void)
}
void test_validPhoneNumber(void)
{
/*Arrange*/
char* validPhoneNumbers[] = {"+4903584736198","+4912345678912","+4987541024534","+4932145784236","+4987264287139"};
bool validPhoneNumbersResult[5];
/*Act*/
for(int i =0;i<5;i++)
{
validPhoneNumbersResult[i] = isValidPhoneNumber(validPhoneNumbers[i]);
}
/*Assert*/
for(int i=0;i<5;i++)
{
TEST_ASSERT_TRUE(validPhoneNumbersResult[i]);
}
}
void test_invalidPhoneNumber(void)
{
/*Arrange*/
char* invalidPhoneNumbers[] = {"+490358473619812","+6112345678912","+498754","-4932145784236","123"};
bool invalidPhoneNumbersResult[2];
/*Act*/
for(int i =0;i<5;i++)
{
invalidPhoneNumbersResult[i] = isValidPhoneNumber(invalidPhoneNumbers[i]);
}
/*Assert*/
for(int i=0;i<5;i++)
{
TEST_ASSERT_FALSE(invalidPhoneNumbersResult[i]);
}
}
#endif // TEST
Loading…
Cancel
Save