From 6a1e132e53d6ca1d147f8499663f59341826aac1 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 6 Feb 2023 20:19:42 +0100 Subject: [PATCH] refactoring: replaced 4 arrays in the unit tests of the function storeEmployeeData() with one matrix to avoid repeated code and removed unnecessary lines. --- tests/test_createEmployeeAccount.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index df336c1..4db4ca1 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -147,29 +147,22 @@ void test_verifyPasswordFailure() void test_employeesDataStoringSuccess(void) { /*Arrange*/ + char*data[][4] ={ + {"John","Doe","fulda,leipzigerstr12","+4926428421469"}, + {"Jane","Done","fulda,leipzigerstr13","+4932517359874"}, + {"Foo","Bar","fulda,leipzigerstr14","+4913598765315"}, + {"Mustermann","Mustermanpass","fulda,leipzigerstr16","+4938197853812"} + }; + bool creationExpectation = true; - char* firstNames[5] = {"John","Jane","Foo","Fizz","Mustermann"}; - char* lastNames[5] = {"Doe","Done","Bar","Buzz","Mustermanpass"}; - char* adress[5] = {"fulda,leipzigerstr12","fulda,leipzigerstr13","fulda,leipzigerstr14","fulda,leipzigerstr15","fulda,leipzigerstr16"}; - char* phoneNumber[5] = {"+4926428421469","+4932517359874","+4913598765315","+4968145725873","+4938197853812"}; - bool creationResult[5]; - - /*Act*/ - - for(int i=0;i<5;i++) - { - creationResult[i] = storeEmployeeData(firstNames[i],lastNames[i],adress[i],phoneNumber[i]); - } - - /*Assert*/ + /*Act and Assert*/ - for(int i=0;i<5;i++) + for(int i=0;i<4;i++) { - TEST_ASSERT_TRUE(creationResult[i]); + bool creationResult = storeEmployeeData(data[i][0],data[i][1],data[i][2],data[i][3]); + TEST_ASSERT_EQUAL(creationExpectation,creationResult); } - - } void test_employeeCreatedSuccessfully(void)