From 95aadea7bb70795c785beebfd73e9bce92af38ba Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 6 Feb 2023 07:32:32 +0100 Subject: [PATCH] refactoring: replaced the redundant arrays in the unit tests of verifyPassword() function with a matrix for better readability --- tests/test_createEmployeeAccount.c | 57 ++++++++++++++++++------------ 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index 456655e..1f4d3b2 100644 --- a/tests/test_createEmployeeAccount.c +++ b/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]; - - /*Act*/ - - for(int i=0; i<10; i++) - { - result[i] = verifyPassword(password[i],confirmation[i]); - } + 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; - /*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)