Browse Source

implement unit tests for the new function isvalidName().

remotes/origin/feature/employees-infos-access
fdai7207 2 years ago
parent
commit
80b26f2a6d
  1. 19
      src/createEmployeeAccount.c
  2. 1
      src/createEmployeeAccount.h
  3. 50
      tests/test_createEmployeeAccount.c

19
src/createEmployeeAccount.c

@ -48,6 +48,24 @@ bool isValidPassword( char *password, int minimumLength)
} }
bool isValidName(char* name, int minimalLength)
{
if(strlen(name) < minimalLength)
{
return false;
}
for(int i = 0;i<strlen(name);i++)
{
if(isdigit(name[i])||ispunct(name[i])||isspace(name[i]))
{
return false;
}
}
return true;
}
int StringLengthCounter(char* string) int StringLengthCounter(char* string)
{ {
int characterCounter = 0; int characterCounter = 0;
@ -112,6 +130,7 @@ void getNewEmployeeCredentials()
const int maxLength = 21; const int maxLength = 21;
char employeeId[maxLength]; char employeeId[maxLength];
const int minPasswordLength = 5; const int minPasswordLength = 5;
const int minimumNameLength = 4;
char employeePassword[maxLength]; char employeePassword[maxLength];
char passwordVerfication[maxLength]; char passwordVerfication[maxLength];

1
src/createEmployeeAccount.h

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

50
tests/test_createEmployeeAccount.c

@ -147,7 +147,7 @@ void test_verifyPasswordFailure()
void test_employeesDataStoringSuccess(void) void test_employeesDataStoringSuccess(void)
{ {
/*Arrange*/ /*Arrange*/
char*data[][4] ={
char* data[][4] ={
{"John","Doe","fulda,leipzigerstr12","+4926428421469"}, {"John","Doe","fulda,leipzigerstr12","+4926428421469"},
{"Jane","Done","fulda,leipzigerstr13","+4932517359874"}, {"Jane","Done","fulda,leipzigerstr13","+4932517359874"},
{"Foo","Bar","fulda,leipzigerstr14","+4913598765315"}, {"Foo","Bar","fulda,leipzigerstr14","+4913598765315"},
@ -190,4 +190,52 @@ void test_employeeCreatedSuccessfully(void)
} }
void test_validName(void)
{
/*Arrange*/
char* validNames[] = {"John","Jane","Fizz","Foo","Atharva","Can","Julius","Haytham","Mohamed","Shivam"};
int minimalLength = 4;
bool validNamesResult[10];
/*Act*/
for(int i = 0;i<10;i++)
{
validNamesResult[i] = isValidName(validNames[i],minimalLength);
}
/*Assert*/
for(int i = 0;i<10;i++)
{
TEST_ASSERT_TRUE(validNames[i]);
}
}
void test_invalidName(void)
{
/*Arrange*/
char* invalidNames[] = {"Jo hn","Jane.","Fizz36","Foo8","Ath,arva","C .a1n","Jul132ius","123Haytham",".Mohamed"," Shivam"};
int minimalLength = 4;
bool invalidNamesResult[10];
/*Act*/
for(int i = 0;i<10;i++)
{
invalidNamesResult[i] = isValidName(invalidNames[i],minimalLength);
}
/*Assert*/
for(int i = 0;i<10;i++)
{
TEST_ASSERT_FALSE(invalidNamesResult[i]);
}
}
#endif // TEST #endif // TEST
Loading…
Cancel
Save