From 4c49a78378b0668c1b378d6ed4027f6426958880 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 8 Feb 2023 02:31:37 +0100 Subject: [PATCH] refactoring : removed code duplicates for better readability in the unit tests of the function isValidPhoneNumber(). --- tests/test_createEmployeeAccount.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c index d1c369e..fcd24d3 100644 --- a/tests/test_createEmployeeAccount.c +++ b/tests/test_createEmployeeAccount.c @@ -230,18 +230,13 @@ void test_validPhoneNumber(void) { /*Arrange*/ char* validPhoneNumbers[] = {"+4903584736198","+4912345678912","+4987541024534","+4932145784236","+4987264287139"}; - bool validPhoneNumbersResult[5]; + bool validPhoneNumbersExpectation = true; - /*Act*/ + /*Act and Assert*/ for(int i =0;i<5;i++) { - validPhoneNumbersResult[i] = isValidPhoneNumber(validPhoneNumbers[i]); - } - - /*Assert*/ - for(int i=0;i<5;i++) - { - TEST_ASSERT_TRUE(validPhoneNumbersResult[i]); + bool validPhoneNumbersResult = isValidPhoneNumber(validPhoneNumbers[i]); + TEST_ASSERT_EQUAL(validPhoneNumbersExpectation, validPhoneNumbersResult); } } @@ -249,19 +244,15 @@ void test_invalidPhoneNumber(void) { /*Arrange*/ char* invalidPhoneNumbers[] = {"+490358473619812","+6112345678912","+498754","-4932145784236","123"}; - bool invalidPhoneNumbersResult[2]; + bool invalidPhoneNumbersExpectation = false; - /*Act*/ + /*Act and Assert*/ for(int i =0;i<5;i++) { - invalidPhoneNumbersResult[i] = isValidPhoneNumber(invalidPhoneNumbers[i]); + bool invalidPhoneNumbersResult = isValidPhoneNumber(invalidPhoneNumbers[i]); + TEST_ASSERT_EQUAL(invalidPhoneNumbersExpectation,invalidPhoneNumbersResult); } - /*Assert*/ - for(int i=0;i<5;i++) - { - TEST_ASSERT_FALSE(invalidPhoneNumbersResult[i]); - } } #endif // TEST