Browse Source

implement unit tests for the function isValidPassword().

remotes/origin/feature/employees-infos-access
fdai7207 2 years ago
parent
commit
17327b8e43
  1. 45
      src/createEmployeeAccount.c
  2. 2
      src/createEmployeeAccount.h
  3. 1
      src/employeeList.txt
  4. 48
      tests/test_createEmployeeAccount.c

45
src/createEmployeeAccount.c

@ -16,6 +16,38 @@ int StringLengthCounter(char* string)
return characterCounter; return characterCounter;
} }
bool isValidPassword(char* employeePassword, int minimumStringLength)
{
char* stringpointer = employeePassword;
int employeePasswordLength = 0;
bool letterFound = false, punctuationFound = false, numberFound = false;
while(*stringpointer!='\0')
{
if(isalpha(* stringpointer))
{
letterFound = true;
}
else if(isdigit(* stringpointer))
{
numberFound = true;
}
else if(ispunct(* stringpointer))
{
punctuationFound = true;
}
if( employeePasswordLength >= minimumStringLength && letterFound && numberFound && punctuationFound)
{
return true;
}
++stringpointer;
++employeePasswordLength;
}
return false;
}
bool isValidEmployeeID(const char* employeeId, int maximumStringLength) bool isValidEmployeeID(const char* employeeId, int maximumStringLength)
{ {
@ -54,9 +86,10 @@ bool createNewEmployee(char* employeeId, char* employeePassword)
void getNewEmployeeCredentials() void getNewEmployeeCredentials()
{ {
const int employeeIdlength = 21;
char employeeId[employeeIdlength];
char employeePassword[employeeIdlength];
const int employeeIdLength = 21;
char employeeId[employeeIdLength];
const int minimumPasswordLength = 5;
char employeePassword[minimumPasswordLength];
printf("please enter your wished Id :\n"); printf("please enter your wished Id :\n");
@ -64,15 +97,15 @@ void getNewEmployeeCredentials()
scanf(" %[^\n]s",employeeId); scanf(" %[^\n]s",employeeId);
employeeId[employeeIdlength] = '\0';
employeeId[employeeIdLength] = '\0';
printf("\nplease enter your wished Password :\n"); printf("\nplease enter your wished Password :\n");
scanf("%s",employeePassword); scanf("%s",employeePassword);
employeePassword[employeeIdlength] = '\0';
employeePassword[strlen(employeePassword)] = '\0';
if(isValidEmployeeID(employeeId,employeeIdlength))
if(isValidEmployeeID(employeeId,employeeIdLength))
{ {
createNewEmployee(employeeId,employeePassword) ? printf("\n\n Account created successfully !\n\n") : printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); createNewEmployee(employeeId,employeePassword) ? printf("\n\n Account created successfully !\n\n") : printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n");
} }

2
src/createEmployeeAccount.h

@ -5,8 +5,10 @@
#include<stdlib.h> #include<stdlib.h>
#include<stdbool.h> #include<stdbool.h>
#include<string.h> #include<string.h>
#include<ctype.h>
bool isValidEmployeeID(const char* employee, int maximumLength); bool isValidEmployeeID(const char* employee, int maximumLength);
bool isValidPassword(char* employeePassword, int minimumStringLength);
bool createNewEmployee(char* employeeId, char* employeePassword); bool createNewEmployee(char* employeeId, char* employeePassword);
int StringLengthCounter(char* string); int StringLengthCounter(char* string);

1
src/employeeList.txt

@ -9,4 +9,3 @@ Julius Insertcatfdai7057
Mohamed MDfdai6618 Mohamed MDfdai6618
Shivam Schivam007fdlt3781 Shivam Schivam007fdlt3781

48
tests/test_createEmployeeAccount.c

@ -49,6 +49,54 @@ void test_isNotValidEmployeeID(void)
} }
void test_validEmployeePassword(void)
{
/*Arrange*/
char* validPassword [] = {"Atharva.123","02.September.2023","fdai7207.","array[20]","malloc(20*sizeof(int))","12.2E1234"};
int minimalLength = 8;
bool validPasswordResult[6];
/*Act*/
for(int i=0; i<6; i++)
{
validPasswordResult[i] = isValidPassword(validPassword[i],minimalLength);
}
/*Assert*/
for(int i=0; i<6; i++)
{
TEST_ASSERT_TRUE(validPasswordResult[i]);
}
}
void test_invalidEmployeePassword(void)
{
/*Arrange*/
char* invalidPassword [] = {"fizzbuzzio","02.09.2023",".^^_*+/-.","RTX4050ti","Can","github.com/bankmanagement-system"};
int minimalLength = 8;
bool invalidPasswordResult[6];
/*Act*/
for(int i=0; i<6; i++)
{
invalidPasswordResult[i] = isValidPassword(invalidPassword[i],minimalLength);
}
/*Assert*/
for(int i=0; i<6; i++)
{
TEST_ASSERT_FALSE(invalidPasswordResult[i]);
}
}
void test_employeeCreatedSuccessfully(void) void test_employeeCreatedSuccessfully(void)
{ {
/*Arrange*/ /*Arrange*/

Loading…
Cancel
Save