Browse Source

refactoring: replaced the redundant arrays in the unit tests of verifyPassword() function with a matrix for better readability

remotes/origin/feature/employees-infos-access
fdai7207 2 years ago
parent
commit
95aadea7bb
  1. 57
      tests/test_createEmployeeAccount.c

57
tests/test_createEmployeeAccount.c

@ -91,22 +91,27 @@ void test_verifyPasswordSuccess()
{
/*Arrange*/
char* password[10] = {"Atharva123.","fdai.7207","fizz.buzz132","23.March.1999","John.doe99","foo/bar2","fizz+3buzz","gitlab2.com","4test:all","WS-2023"};
char* confirmation[10] = {"Atharva123.","fdai.7207","fizz.buzz132","23.March.1999","John.doe99","foo/bar2","fizz+3buzz","gitlab2.com","4test:all","WS-2023"};
bool result[10];
char* passwordsAndVerifications[][2] = {
{"Atharva123.","Atharva123."},
{"fdai.7207","fdai.7207"},
{"fizz.buzz132","fizz.buzz132"},
{"23.March.1999","23.March.1999"},
{"John.doe99","John.doe99"},
{"foo/bar2","foo/bar2"},
{"fizz+3buzz","fizz+3buzz"},
{"gitlab2.com","gitlab2.com"},
{"4test:all","4test:all"},
{"WS-2023","WS-2023"}
};
bool expectation = true;
/*Act*/
for(int i=0; i<10; i++)
{
result[i] = verifyPassword(password[i],confirmation[i]);
}
/*Assert*/
/*Act and Assert*/
for(int i=0; i<10; i++)
{
TEST_ASSERT_TRUE(result[i]);
bool result = verifyPassword(passwordsAndVerifications[i][0],passwordsAndVerifications[i][1]);
TEST_ASSERT_EQUAL(expectation,result);
}
}
@ -114,23 +119,29 @@ void test_verifyPasswordFailure()
{
/*Arrange*/
char* password[10] = {"Atharva123.","fdai.7207","fizz.buzz132","23.March.1999","John.doe99","foo/bar2","fizz+3buzz","gitlab2.com","4test:all","WS-2023"};
char* confirmation[10] = {"Atharva123","fdai.72","invalidPassword","23.May.1999","Jane.doe99","foo*bar3","fizz-3buzz","github.com","4ceedlingtest:all","SS-2023"};
bool result[10];
char* passwordsAndVerifications[][2] = {
{"Atharva123.","Atharva123"},
{"fdai.7207","fdai.72"},
{"fizz.buzz132","invalidPassword"},
{"23.March.1999","23.May.1999"},
{"John.doe99","Jane.doe99"},
{"foo/bar2","foo*bar3"},
{"fizz+3buzz","fizz-3buzz"},
{"gitlab2.com","github.com"},
{"4test:all","4ceedlingtest:all"},
{"WS-2023","SS-2023"}
};
bool expectation = false;
/*Act*/
/*Act and Assert*/
for(int i=0; i<10; i++)
{
result[i] = verifyPassword(password[i],confirmation[i]);
bool result = verifyPassword(passwordsAndVerifications[i][0],passwordsAndVerifications[i][1]);
TEST_ASSERT_EQUAL(expectation,result);
}
/*Assert*/
for(int i=0; i<10; i++)
{
TEST_ASSERT_FALSE(result[i]);
}
}
void test_employeeCreatedSuccessfully(void)

Loading…
Cancel
Save