From a0914aad453363c1ce5866c97745b0af2fd1870c Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Tue, 31 Jan 2023 14:30:31 +0100 Subject: [PATCH] refactoring: removed redundant code in the unit tests of the chooseOption() function. --- tests/test_mainMenu.c | 47 ++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/tests/test_mainMenu.c b/tests/test_mainMenu.c index ea65cc2..af93eaf 100644 --- a/tests/test_mainMenu.c +++ b/tests/test_mainMenu.c @@ -134,25 +134,23 @@ void test_validChoiceInput(void) int validInput[4]; - bool validInputResult[4]; + bool validInputExpected = true; - /*Act*/ + for(int i = 0; i < 4; i++) { validInput[i] = i + 1; } + /*Act and Asssert*/ + for(int i = 0; i < 4; i++) { - validInputResult[i] = chooseOption(validInput[i]); - } - /*Assert*/ + bool validInputResult = chooseOption(validInput[i]); - for(int i = 0; i < 4; i++) - { - TEST_ASSERT_TRUE(validInputResult[i]); + TEST_ASSERT_EQUAL(validInputExpected,validInputResult); } } @@ -165,25 +163,24 @@ void test_invalidChoiceInput_firstCase(void) int invalidInput[100]; - bool invalidInputResult[100]; + bool invalidInputExpected = false; - /*Act*/ + - for(int i = -100; i < 0; i++) + for(int i = -100; i < 1; i++) { invalidInput[i+100] = i; } + /*Act and Assert*/ + for(int i = 0; i < 100; i++) { - invalidInputResult[i] = chooseOption(invalidInput[i]); - } - /*Assert*/ + bool invalidInputResult = chooseOption(invalidInput[i]); + + TEST_ASSERT_EQUAL(invalidInputExpected,invalidInputResult); - for(int i = 0; i < 100; i++) - { - TEST_ASSERT_FALSE(invalidInputResult[i]); } } @@ -196,27 +193,23 @@ void test_invalidChoiceInput_secondCase(void) int invalidInput[100]; - bool invalidInputResult[100]; - - /*Act*/ + bool invalidInputExpected = false; for(int i = 0; i < 100; i++) { invalidInput[i] = i + 5; } - for(int i = 0; i < 100; i++) - { - invalidInputResult[i] = chooseOption(invalidInput[i]); - } - - /*Assert*/ + /*Act and Assert*/ for(int i = 0; i < 100; i++) { - TEST_ASSERT_FALSE(invalidInputResult[i]); + bool invalidInputResult = chooseOption(invalidInput[i]); + + TEST_ASSERT_EQUAL(invalidInputExpected,invalidInputResult); } + }