Browse Source

implement unit tests for the isValidAdress() function.

remotes/origin/backup-for-employees-infos-access
fdai7207 2 years ago
parent
commit
f194873640
  1. 13
      src/createEmployeeAccount.c
  2. 7
      src/createEmployeeAccount.h
  3. 45
      tests/test_createEmployeeAccount.c

13
src/createEmployeeAccount.c

@ -80,20 +80,20 @@ bool isValidPhoneNumber(char *phoneNumber)
return true; return true;
} }
bool isValidAdress(char *street,int houseNumber,char* city,int postalCode)
bool isValidAdress(char *street,char* city,int houseNumber,int postalCode)
{ {
int maximalLength = 20;
int minimalLength = 3;
int lengthMax = 20;
int LengthMin = 3;
bool validStreet = true; bool validStreet = true;
bool validHouseNumber = true; bool validHouseNumber = true;
bool validCity = true; bool validCity = true;
bool validpostalCode = true; bool validpostalCode = true;
if(strlen(street)>20 || strlen(street)<3)
if(strlen(street)>lengthMax || strlen(street)<LengthMin)
{ {
validStreet = false; validStreet = false;
} }
if(strlen(city)>20 || strlen(city)<3)
if(strlen(city)>lengthMax || strlen(city)<LengthMin)
{ {
validCity = false; validCity = false;
} }
@ -105,11 +105,10 @@ bool isValidAdress(char *street,int houseNumber,char* city,int postalCode)
{ {
validpostalCode = false; validpostalCode = false;
} }
if(validStreet && validCity && validHouseNumber && validpostalCode)
if(validStreet==true && validCity==true && validHouseNumber==true && validpostalCode==true)
{ {
return true; return true;
} }
else
{ {
return false; return false;
} }

7
src/createEmployeeAccount.h

@ -23,11 +23,12 @@ typedef struct employeesInformations employeedata;
bool isValidEmployeeID(const char* employee, int maximumLength); bool isValidEmployeeID(const char* employee, int maximumLength);
bool isValidPassword( char* password, int minimumLength); bool isValidPassword( char* password, int minimumLength);
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 isValidName(char* name,int minimalLength);
bool isValidPhoneNumber(char *phoneNumber); bool isValidPhoneNumber(char *phoneNumber);
bool isValidAdress(char *street,char* city,int houseNumber,int postalCode);
bool storeEmployeeData(const char *name,const char *lastName,const char *adress,const char *phoneNumber);
bool verifyPassword(char* enteredPassword,char* passwordConfirmation);
bool createNewEmployee(char* employeeId, char* employeePassword);
int StringLengthCounter(char* string); int StringLengthCounter(char* string);

45
tests/test_createEmployeeAccount.c

@ -240,6 +240,50 @@ void test_validPhoneNumber(void)
} }
} }
void test_isValidAdressSuccess(void)
{
/*Arrange*/
char* validStreet[] = {"LeipzigerStrasse","HannauerLandStra","HenirichStrasse","MAgdeburgerStrasse"};
char* validCity[] = {"Hannover","Frankfurt","Berlin","Fulda"};
int validHouseNumber[4] = {112,365,16,998};
int validPostalCode[4] = {36879,36897,12354,9999};
bool validAdress[4];
/*Act*/
for(int i=0;i<4;i++)
{
validAdress[i] = isValidAdress(validStreet[i],validCity[i],validHouseNumber[i],validPostalCode[i]);
}
/*Assert*/
for(int j=0;j<4;j++)
{
TEST_ASSERT_TRUE(validAdress[j]);
}
}
void test_isValidAdressFailure(void)
{
/*Arrange*/
char* invalidStreet[] = {"LeipzigerStrassehvjhb","HannauerLandStranl","bob",".."};
char* invalidCity[] = {"log","fiz","foo","bar"};
int invalidHouseNumber[4] = {-10,-1,0,99815};
int invalidPostalCode[4] = {-1,10,999,65};
bool invalidAdress[4];
/*Act*/
for(int i=0;i<4;i++)
{
invalidAdress[i] = isValidAdress(invalidStreet[i],invalidCity[i],invalidHouseNumber[i],invalidPostalCode[i]);
}
/*Assert*/
for(int j=0;j<4;j++)
{
TEST_ASSERT_FALSE(invalidAdress[j]);
}
}
void test_invalidPhoneNumber(void) void test_invalidPhoneNumber(void)
{ {
/*Arrange*/ /*Arrange*/
@ -255,4 +299,5 @@ void test_invalidPhoneNumber(void)
} }
#endif // TEST #endif // TEST
Loading…
Cancel
Save