Browse Source
implement unit tests for the function isValidEmployeeID()
remotes/origin/feature/employees-infos-access
implement unit tests for the function isValidEmployeeID()
remotes/origin/feature/employees-infos-access
fdai7207
2 years ago
12 changed files with 173 additions and 51 deletions
-
18build-project.sh
-
20src/createEmployeeAccount.c
-
10src/createEmployeeAccount.h
-
1src/employeeList.txt
-
13src/employeeLogin.c
-
7src/employeeLogin.h
-
2src/main.c
-
7src/mainMenu.c
-
47src/showGeneralInfoEmployee.c
-
3src/showGeneralInfoEmployee.h
-
62tests/test_createEmployeeAccount.c
-
26tests/test_showGeneralInfoEmployee.c
@ -1,13 +1,27 @@ |
|||||
trap 'echo "Interrupted"; rm main; cp employeeLogin.c.bak employeeLogin.c; rm employeeLogin.c.bak; cd ..; rm -r build/; exit' SIGINT |
|
||||
|
trap 'echo "Interrupted"; |
||||
|
rm main; |
||||
|
cp employeeLogin.c.bak employeeLogin.c; |
||||
|
cp mainMenu.c.bak mainMenu.c; |
||||
|
rm employeeLogin.c.bak; |
||||
|
rm mainMenu.c.bak; |
||||
|
cd ..; |
||||
|
rm -r build; exit' SIGINT |
||||
clear |
clear |
||||
ceedling test:all |
ceedling test:all |
||||
|
|
||||
cd src/ |
cd src/ |
||||
cp employeeLogin.c employeeLogin.c.bak |
cp employeeLogin.c employeeLogin.c.bak |
||||
|
cp mainMenu.c mainMenu.c.bak |
||||
|
sed -i 's/employeeLogin.c/employeeLogin.h/g' mainMenu.c |
||||
|
sed -i 's/showGeneralInfoEmployee.c/showGeneralInfoEmployee.h/g' employeeLogin.c |
||||
|
sed -i 's/mainMenu.c/mainMenu.h/g' employeeLogin.c |
||||
sed -i 's/src\///g' employeeLogin.c |
sed -i 's/src\///g' employeeLogin.c |
||||
gcc main.c mainMenu.c -o main |
|
||||
|
gcc main.c mainMenu.c employeeLogin.c showGeneralInfoEmployee.c -o main |
||||
./main |
./main |
||||
rm main |
rm main |
||||
cp employeeLogin.c.bak employeeLogin.c |
cp employeeLogin.c.bak employeeLogin.c |
||||
|
cp mainMenu.c.bak mainMenu.c |
||||
rm employeeLogin.c.bak |
rm employeeLogin.c.bak |
||||
|
rm mainMenu.c.bak |
||||
cd .. |
cd .. |
||||
rm -r build/ |
rm -r build/ |
@ -0,0 +1,20 @@ |
|||||
|
#include "employeeLogin.c" |
||||
|
#include "employeeLogin.h" |
||||
|
#include "createEmployeeAccount.h" |
||||
|
|
||||
|
|
||||
|
bool isValidEmployeeID(char* employeeId) |
||||
|
{ |
||||
|
int characterLimit = 20; |
||||
|
|
||||
|
if(strlen(employeeId)>characterLimit || strchr(employeeId,' ')) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
else |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
|
@ -0,0 +1,10 @@ |
|||||
|
#ifndef CREATEEMPLOYEEACCOUNT_H_ |
||||
|
#define CREATEEMPLOYEEACCOUNT_H_ |
||||
|
|
||||
|
#include<stdio.h> |
||||
|
#include<stdlib.h> |
||||
|
#include<stdbool.h> |
||||
|
#include<string.h> |
||||
|
|
||||
|
bool isValidEmployeeID(char* employee); |
||||
|
#endif |
@ -0,0 +1,62 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "createEmployeeAccount.h" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
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]; |
||||
|
|
||||
|
/*Act*/ |
||||
|
|
||||
|
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]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void test_isNotValidEmployeeID(void) |
||||
|
{ |
||||
|
|
||||
|
/*Arrange*/ |
||||
|
|
||||
|
char* invalidEmployeeId [] = {"Atha rva","Ca n","Geschwindigkeitsbegrenzungen","1234 15","John Doe","fizz Fuzz"}; |
||||
|
bool invalidEmployeeIdResult[6]; |
||||
|
|
||||
|
/*Act*/ |
||||
|
|
||||
|
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]); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#endif // TEST |
Write
Preview
Loading…
Cancel
Save
Reference in new issue