From b7d38fac5eb9a381524dc9b653fdb19899bfa6d5 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sat, 4 Feb 2023 04:38:01 +0100 Subject: [PATCH] refactoring: clean up duplicated code for the createEmployeeAccount.c unit tests. --- src/employeeList.txt | 1 - tests/test_createEmployeeAccount.c | 46 +++++++++--------------------- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/src/employeeList.txt b/src/employeeList.txt index 94986be..ed5a12d 100644 --- a/src/employeeList.txt +++ b/src/employeeList.txt @@ -9,4 +9,3 @@ Julius Insertcatfdai7057 Mohamed MDfdai6618 Shivam Schivam007fdlt3781 - diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index fb6f768..7ce99aa 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -18,20 +18,14 @@ void test_isValidEmployeeID(void) /*Arrange*/ char* validEmployeeId [] = {"Atharva","Can","Haytham","Julius","Mohamed","Shivam","Fizz","Buzz","JohnDoe","Foobar","waz","Objectoriented","INSTITUTIONALISATIOL","Intercommunicational","1234","1.6"}; - bool validEmployeeIdResult[15]; + bool validEmployeeIdExpected = true; - /*Act*/ + /*Act and Assert*/ for(int i=0; i<15; i++) { - validEmployeeIdResult[i] = isValidEmployeeID(validEmployeeId[i]); - } - - /*Assert*/ - - for(int i =0; i<15;i++) - { - TEST_ASSERT_TRUE(validEmployeeIdResult[i]); + bool validEmployeeIdResult = isValidEmployeeID(validEmployeeId[i]); + TEST_ASSERT_EQUAL(validEmployeeIdExpected,validEmployeeIdResult); } } @@ -41,22 +35,16 @@ void test_isNotValidEmployeeID(void) /*Arrange*/ char* invalidEmployeeId [] = {"Atha rva","Ca n","Geschwindigkeitsbegrenzungen","1234 15","John Doe","fizz Fuzz"}; - bool invalidEmployeeIdResult[6]; + bool invalidEmployeeIdExpected = false; - /*Act*/ + /*Act and Assert*/ for(int i=0; i<6; i++) { - invalidEmployeeIdResult[i] = isValidEmployeeID(invalidEmployeeId[i]); - } - - /*Assert*/ - - for(int i =0; i<6;i++) - { - TEST_ASSERT_FALSE(invalidEmployeeIdResult[i]); + bool invalidEmployeeIdResult = isValidEmployeeID(invalidEmployeeId[i]); + TEST_ASSERT_EQUAL(invalidEmployeeIdExpected,invalidEmployeeIdResult); } - + } void test_employeeCreatedSuccessfully(void) @@ -71,21 +59,15 @@ void test_employeeCreatedSuccessfully(void) {"MusterFrau", "MusterFrauPassword"} }; - bool expected[6] = {true,true,true,true,true,true}; - bool result[6]; + bool expected = true; + bool result; - /*Act*/ + /*Act and Assert*/ for(int i=0; i<6;i++) { - result[i] = createNewEmployee(potentialEmployees[i][0],potentialEmployees[i][1]); - } - - /*Assert*/ - - for(int i=0; i<6;i++) - { - TEST_ASSERT_EQUAL(expected[i],result[i]); + result = createNewEmployee(potentialEmployees[i][0],potentialEmployees[i][1]); + TEST_ASSERT_EQUAL(expected,result); } }