From be083578653005756d80ca32cad372f8287c12a7 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Wed, 1 Feb 2023 20:12:06 +0100 Subject: [PATCH] refactoring: removed redundant code from the unit test file test_employeeLogin.c, changed variable names and added som comments . --- .../.test_employeeLogin.c.swp | Bin 12288 -> 16384 bytes test/test_employeeLogin.c | 159 +++++++----------- 2 files changed, 62 insertions(+), 97 deletions(-) rename src/.employeeLogin.c.swp => test/.test_employeeLogin.c.swp (57%) diff --git a/src/.employeeLogin.c.swp b/test/.test_employeeLogin.c.swp similarity index 57% rename from src/.employeeLogin.c.swp rename to test/.test_employeeLogin.c.swp index a2975fcb31a1a48c8e9e0e9a4ff11c9c866b60ce..77752368280750880b47ea9f9ce5e66997e1bc68 100644 GIT binary patch literal 16384 zcmeI3TZ|J`7{`xzfmIh#qVhNv5*H}j3$nYq+zMU8E?X7al_+kSVP?7=ww>9`Oc!@+ z4old(g(`pRrIh)^1 zr{_E0IrGi`oar|VyQ23Gr-VCuqXcCUA?EQj(x+<)`C}O&d2zUfMz^`)WPgvB?F1#8Q#cm#L^cm#L^cm#L^cm#L^cm#L^ z{u2?frsk2oIFotK*-Se7E9&-FI>%Qz`^W0)okPCk5#SNv5#SNv5#SNv5#SNv5#SNv z5#SNv5#SNH3?m@QguITVzIY7=hkyTf^Z$!C5OM*04ZZ>&gO9*5a1kKi1b z1v6k2Yz0ZM86?0)umP+G>%bCl3%D5&@KYBdKY;gu1y+L#3kZ1|jDuI^6Y@NG4(tXh z*bY)44#MDea17VzFqj1;paFW_PF_vOo8S$w7mR@n=miVFeDDpf@p14LI15gLQ{V(R zkB2`Wf&*Yb$b$_a2BN@M1Qb=X1Vb@P1QX%>o-b{;Ba2GcB-2}w zOt{_|9S;lkdNa|?BsN~#bD8y@(~Tb5zq&3uD5z`uuvxisxi`MZiiBhdq9zLo(^L#= zMTD?Q+NOGD<5(@r(Qx&zGH4rhu_7Q+gQN?)c1k&vD&b{1BWH-EP*|urni5TOk8a4J zN<04k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b_6>LqTmzfn5_k@bf``FxhZ*|`Tn8KAWv~ofFbynl0z3pB1b2bI zq32)V4e&bH0$0IH;38NAO7kUPno+=Re)UHeyeZ5#j zl6M9A($0LmniEEzOdPAc9`p#q+SCh)`#uE@C9a?(@CfoYMAz%MA|kReD&o=>G; mSw&CM(Tv;SgBDFH5wBY?U?dOwM~{@ z@_&{h!I!gubhma~SzbhZG!uqVu%f)nmMU$qlJH~EH#BUrUe8zG+w2QbAUiZGognJ+ z#0zAs0#Qo2d_~a7b|w$`!b#FqYq`n#WUjt)Hj7r>DQ`%H?FxJO=}5HkDWb>ym>Lb5 zsxUP~wP8PZ#3_S>9PCCv&}`P=LVK(Ml}l=HrnS1m-qTKRvaV+SVdQ|LmQJMFK$bCO zNHv`TyH22i8ESB*%Bt)6LZ`u#Ity%NF@JcFb4FoF7*8e0aW&Dx07Cwwv&o2&qHbU~QnU@1zbRtsT4hUp&xu z^f4~-G!jWKk~C2qCCB!ISXkP#mKP@jN1~XiA{_pudUAVHg+0})+U@PC5m{oXJJs}& z8?oXfvb&)*tO)sVtRGi}PMxB`aayHXI!^zp6h~Dpv8Vf!|J{AhA?x3}K0H#pyWRN; zG39nz2}>w`~j1NQ0Ue&gB)oG+yc>gS|Qyg-49BowfTifodk!P={nu`J20xd9?~vw;h#%PVGKY fiH&;F_IqtX<-Ts|m-KFV;8B-*a!$zJ7<&H!zLM@d diff --git a/test/test_employeeLogin.c b/test/test_employeeLogin.c index 5cfdfdf..8e2d8de 100644 --- a/test/test_employeeLogin.c +++ b/test/test_employeeLogin.c @@ -17,130 +17,95 @@ void test_SuccessfulLoginEmployee_(void) //test case : 0 - //Arrange - char* ExistingEmployee1 = "Atharva"; - char* ExistingPassword1 = "Atharvafdai7514"; - - char* ExistingEmployee2 = "Can"; - char* ExistingPassword2 = "BlooMaskfdlt3817"; + /*Arrange*/ + + char* validEmployeesCredentials[][2] = { + {"Atharva", "Atharvafdai7514"}, + {"Can", "BlooMaskfdlt3817"}, + {"Haytham", "TimoDLfdai7207"}, + {"Julius", "Insertcatfdai7057"}, + {"Mohamed", "MDfdai6618"}, + {"Shivam", "Schivam007fdlt3781"} + }; + /*Act and Assert*/ - char* ExistingEmployee3 = "Haytham"; - char* ExistingPassword3 = "TimoDLfdai7207"; + int expected[] = {1,1,1,1,1,1}; - char* ExistingEmployee4 = "Julius"; - char* ExistingPassword4 = "Insertcatfdai7057"; + for(int i=0; i<6; i++) + { + + int result = checkEmployeeCredentials(validEmployeesCredentials[i][0], validEmployeesCredentials[i][1]); + + TEST_ASSERT_EQUAL_INT(expected[i],result); + + } - char* ExistingEmployee5 = "Mohamed"; - char* ExistingPassword5 = "MDfdai6618"; - char* ExistingEmployee6 = "Shivam"; - char* ExistingPassword6 = "Schivam007fdlt3781"; - - //Act - - int result1 = checkEmployeeCredentials(ExistingEmployee1,ExistingPassword1); - int result2 = checkEmployeeCredentials(ExistingEmployee2,ExistingPassword2); - int result3 = checkEmployeeCredentials(ExistingEmployee3,ExistingPassword3); - int result4 = checkEmployeeCredentials(ExistingEmployee4,ExistingPassword4); - int result5 = checkEmployeeCredentials(ExistingEmployee5,ExistingPassword5); - int result6 = checkEmployeeCredentials(ExistingEmployee6,ExistingPassword6); - - //Assert - TEST_ASSERT_EQUAL_INT(1,result1); - TEST_ASSERT_EQUAL_INT(1,result2); - TEST_ASSERT_EQUAL_INT(1,result3); - TEST_ASSERT_EQUAL_INT(1,result4); - TEST_ASSERT_EQUAL_INT(1,result5); - TEST_ASSERT_EQUAL_INT(1,result6); } void test_WrongInfosLoginEmployee(void) { //test case : 1 + /*Arrange*/ + + char* wrongEmployeesCredentials[][2] = { + {"Atharva", "doe"}, + {"Can", "Bar"}, + {"Haytham", "buzz"}, + {"Julius", "fizz"}, + {"Mohamed", "muster"}, + {"Shivam", "TimoDL"} + }; - //Arrange - char* wrongInfoEmployee1 = "Atharva"; - char* wrongInfoPassword1 = "doe"; - - char* wrongInfoEmployee2 = "Can"; - char* wrongInfoPassword2 = "Bar"; + /*Act and Assert*/ - char* wrongInfoEmployee3 = "Haytham"; - char* wrongInfoPassword3 = "buzz"; + int expected[] = {2,2,2,2,2,2}; - char* wrongInfoEmployee4 = "Julius"; - char* wrongInfoPassword4 = "Musterpass"; + for(int i=0; i<6; i++) + { - char* wrongInfoEmployee5 = "Mohamed"; - char* wrongInfoPassword5 = "Irgendwas"; + int result = checkEmployeeCredentials(wrongEmployeesCredentials[i][0], wrongEmployeesCredentials[i][1]); - char* wrongInfoEmployee6 = "Shivam"; - char* wrongInfoPassword6 = "John"; + TEST_ASSERT_EQUAL_INT(expected[i],result); - //Act + } - int result1 = checkEmployeeCredentials(wrongInfoEmployee1,wrongInfoPassword1); - int result2 = checkEmployeeCredentials(wrongInfoEmployee2,wrongInfoPassword2); - int result3 = checkEmployeeCredentials(wrongInfoEmployee3,wrongInfoPassword3); - int result4 = checkEmployeeCredentials(wrongInfoEmployee4,wrongInfoPassword4); - int result5 = checkEmployeeCredentials(wrongInfoEmployee5,wrongInfoPassword5); - int result6 = checkEmployeeCredentials(wrongInfoEmployee6,wrongInfoPassword6); - - //Assert +} - TEST_ASSERT_EQUAL_INT(2,result1); - TEST_ASSERT_EQUAL_INT(2,result2); - TEST_ASSERT_EQUAL_INT(2,result3); - TEST_ASSERT_EQUAL_INT(2,result4); - TEST_ASSERT_EQUAL_INT(2,result5); - TEST_ASSERT_EQUAL_INT(2,result6); -} void test_MissingLoginEmployee(void) { //test case : 2 + /*Arrange*/ + + char* missingEmployeesCredentials[][2] = { + {"John", "doe"}, + {"Jane", "Doe"}, + {"Foo", "Bar"}, + {"Fizz", "Buzz"}, + {"Musterman", "Mustermanpassword"}, + {"Musterfrau", "Musterfraupassword"} + }; + + int expected[] = {0,0,0,0,0,0}; + + /*Act and Assert*/ + + for(int i=0; i<6; i++) + { + + int result = checkEmployeeCredentials(missingEmployeesCredentials[i][0], missingEmployeesCredentials[i][1]); + + TEST_ASSERT_EQUAL_INT(expected[i],result); + + } - //Arrange - - char* missingEmployee1 = "John"; - char* missingPassword1 = "Doe"; - - char* missingEmployee2 = "Jane"; - char* missingPassword2 = "Doe"; - - char* missingEmployee3 = "Foo"; - char* missingPassword3 = "Bar"; - - char* missingEmployee4 = "Mustermann"; - char* missingPassword4 = "PassMustermann"; - - char* missingEmployee5 = "Musterfrau"; - char* missingPassword5 = "PassMusterfrau"; - - char* missingEmployee6 = "Fizz"; - char* missingPassword6 = "Buzz"; - - //Act - int result1 = checkEmployeeCredentials(missingEmployee1,missingPassword1); - int result2 = checkEmployeeCredentials(missingEmployee2,missingPassword2); - int result3 = checkEmployeeCredentials(missingEmployee3,missingPassword3); - int result4 = checkEmployeeCredentials(missingEmployee4,missingPassword4); - int result5 = checkEmployeeCredentials(missingEmployee5,missingPassword5); - int result6 = checkEmployeeCredentials(missingEmployee6,missingPassword6); - - //Assert - TEST_ASSERT_EQUAL_INT(0,result1); - TEST_ASSERT_EQUAL_INT(0,result2); - TEST_ASSERT_EQUAL_INT(0,result3); - TEST_ASSERT_EQUAL_INT(0,result4); - TEST_ASSERT_EQUAL_INT(0,result5); - TEST_ASSERT_EQUAL_INT(0,result6); - + } #endif // TEST