From a061383579a37885a155156e69cb9d8885af7912 Mon Sep 17 00:00:00 2001 From: fdai7057 Date: Sun, 22 Jan 2023 12:03:00 +0100 Subject: [PATCH] refactoring: Modified unit test for function error(). Replaced variables with arras and consecutive execution of assertion calls with for-loops and added test cases for valid error codes. --- tests/test_Error.c | 56 +++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/tests/test_Error.c b/tests/test_Error.c index ba28ac2..c4afd6d 100644 --- a/tests/test_Error.c +++ b/tests/test_Error.c @@ -12,29 +12,39 @@ void test_error() /*arrange*/ srand(time(0)); int bound = 1000; - int val1,val2,val3,val4,val5,val6,val7,val8,val9,val10; + int invalidErrorCodes_1[bound]; + int invalidErrorCodesLarge_2[bound]; + int invalidErrorCodesLargest_3[bound]; - /*act*/ - val1 = rand() % 1000 + 1; - val2 = rand() % 1000 + 1; - val3 = rand() % 1000 + 1; - val4 = rand() % 1000 + 1; - val5 = rand() % 1000 + 1; - val6 = rand() % 1000 + 1; - val7 = rand() % 1000 + 1; - val8 = rand() % 1000 + 1; - val9 = rand() % 1000 + 1; - val10 = rand() % 1000 + 1; + int validErrorCodeUnsuccessfulLogin[bound]; + int validErrorCodeMaximumNumberOfAttempts[bound]; + int validErrorCodeNoMenuEntryForNumber[bound]; - /*assertions*/ - TEST_ASSERT_EQUAL_INT(0,error(val1)); - TEST_ASSERT_EQUAL_INT(0,error(val2)); - TEST_ASSERT_EQUAL_INT(0,error(val3)); - TEST_ASSERT_EQUAL_INT(0,error(val4)); - TEST_ASSERT_EQUAL_INT(0,error(val5)); - TEST_ASSERT_EQUAL_INT(0,error(val6)); - TEST_ASSERT_EQUAL_INT(0,error(val7)); - TEST_ASSERT_EQUAL_INT(0,error(val8)); - TEST_ASSERT_EQUAL_INT(0,error(val9)); - TEST_ASSERT_EQUAL_INT(0,error(val10)); + for(int i=0;i