Browse Source

refactoring: modification of unit tests for function generateID(), add array for values and for-loop to check assertions

remotes/origin/feature/customer-creation
fdai7057 2 years ago
parent
commit
08444292cb
  1. 16
      src/CreateCustomer.c
  2. 7
      src/main.c
  3. 9
      team.md
  4. 2
      tests/build/test/cache/defines_dependency.yml
  5. 2
      tests/build/test/cache/input.yml
  6. 53
      tests/build/test/cache/test_CreateCustomer.c
  7. 5
      tests/build/test/dependencies/CreateCustomer.d
  8. 4
      tests/build/test/dependencies/test_CreateCustomer.d
  9. 4
      tests/build/test/dependencies/test_CreateCustomer_runner.d
  10. BIN
      tests/build/test/out/c/CreateCustomer.o
  11. BIN
      tests/build/test/out/c/test_CreateCustomer.o
  12. BIN
      tests/build/test/out/c/test_CreateCustomer_runner.o
  13. BIN
      tests/build/test/out/test_CreateCustomer.out
  14. 53
      tests/build/test/preprocess/files/test_CreateCustomer.c
  15. 3
      tests/build/test/preprocess/includes/test_CreateCustomer.c
  16. 65553
      tests/build/test/results/test_CreateCustomer.pass
  17. 81
      tests/build/test/runners/test_CreateCustomer_runner.c
  18. 2
      tests/project.yml
  19. 7
      tests/test/test_CreateCustomer.c

16
src/CreateCustomer.c

@ -1,20 +1,18 @@
#include "CreateCustomer.h"
/*Code written by Julius Philipp Engel, fdai7057*/
/*
int main()
{
collectCustomerProperties();
}
}*/
int generateID()
{
srand(time(0));
const int MIN = 1000000, MAX = 10000000;
int p_val = rand() % (MAX);
if(p_val<MIN)
{
p_val += MIN;
}
return p_val;
srand(clock());
const int MIN = 1000000, MAX = 9000001;
int pseudoRandomIDForCustomer = (rand() % MAX) + MIN;
return pseudoRandomIDForCustomer;
}
void collectCustomerProperties()

7
src/main.c

@ -1,7 +0,0 @@
#include <stdio.h>
int main()
{
return 0;
}

9
team.md

@ -1,9 +0,0 @@
# Bankmanagement-System
- Can Hacioglu, Fdlt3817
- Atharva Kishor Naik, fdai7514
- Julius Philipp Engel, fdai7057
- Shivam Chaudhary, fdlt3781
- Mohamed Yahya Dahi, fdai6618
- Haytham Daoula, fdai7207

2
tests/build/test/cache/defines_dependency.yml

@ -5,3 +5,5 @@ src/main.c:
- TEST
"/home/julius/Documents/Studium/Informatik/1. Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/CreateCustomer.c":
- TEST
"../src/CreateCustomer.c":
- TEST

2
tests/build/test/cache/input.yml

@ -26,7 +26,7 @@
- "+:test/**"
- "-:test/support"
:source:
- "/home/julius/Documents/Studium/Informatik/1. Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/**"
- "../src/**"
:support:
- test/support
:include: []

53
tests/build/test/cache/test_CreateCustomer.c

@ -0,0 +1,53 @@
#include "../src/CreateCustomer.h"
#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h"
void setUp(){}
void tearDown(){}
void test_generateID(){
const int test_values =
(0x7fff * 2 + 1)
;
int *numbers = calloc(test_values, sizeof(int));
for(int i=0;i<test_values;++i)
{
*(numbers+i) = generateID();
printf("%d\n", *(numbers+i));
}
int delta = 5000000, expected = 5000000;
for(int i=0;i<test_values;++i)
{
UnityAssertNumbersWithin( ((delta)), (UNITY_INT) ((expected)), (UNITY_INT) ((*(numbers+i))), (
((void *)0)
), (UNITY_UINT)(23), UNITY_DISPLAY_STYLE_INT);
}
}

5
tests/build/test/dependencies/CreateCustomer.d

@ -1,3 +1,2 @@
build/test/out/c/CreateCustomer.o: \
/home/julius/Documents/Studium/Informatik/1.\ Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/CreateCustomer.c \
/home/julius/Documents/Studium/Informatik/1.\ Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/CreateCustomer.h
build/test/out/c/CreateCustomer.o: ../src/CreateCustomer.c \
../src/CreateCustomer.h ../src/CustomerProperties.h

4
tests/build/test/dependencies/test_CreateCustomer.d

@ -0,0 +1,4 @@
build/test/out/c/test_CreateCustomer.o: test/test_CreateCustomer.c \
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \
../src/CreateCustomer.h ../src/CustomerProperties.h

4
tests/build/test/dependencies/test_CreateCustomer_runner.d

@ -0,0 +1,4 @@
build/test/out/c/test_CreateCustomer_runner.o: \
build/test/runners/test_CreateCustomer_runner.c \
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h

BIN
tests/build/test/out/c/CreateCustomer.o

BIN
tests/build/test/out/c/test_CreateCustomer.o

BIN
tests/build/test/out/c/test_CreateCustomer_runner.o

BIN
tests/build/test/out/test_CreateCustomer.out

53
tests/build/test/preprocess/files/test_CreateCustomer.c

@ -0,0 +1,53 @@
#include "../src/CreateCustomer.h"
#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h"
void setUp(){}
void tearDown(){}
void test_generateID(){
const int test_values =
(0x7fff * 2 + 1)
;
int *numbers = calloc(test_values, sizeof(int));
for(int i=0;i<test_values;++i)
{
*(numbers+i) = generateID();
printf("%d\n", *(numbers+i));
}
int delta = 5000000, expected = 5000000;
for(int i=0;i<test_values;++i)
{
UnityAssertNumbersWithin( ((delta)), (UNITY_INT) ((expected)), (UNITY_INT) ((*(numbers+i))), (
((void *)0)
), (UNITY_UINT)(23), UNITY_DISPLAY_STYLE_INT);
}
}

3
tests/build/test/preprocess/includes/test_CreateCustomer.c

@ -0,0 +1,3 @@
---
- "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h"
- "../src/CreateCustomer.h"

65553
tests/build/test/results/test_CreateCustomer.pass
File diff suppressed because it is too large
View File

81
tests/build/test/runners/test_CreateCustomer_runner.c

@ -0,0 +1,81 @@
/* AUTOGENERATED FILE. DO NOT EDIT. */
/*=======Automagically Detected Files To Include=====*/
#include "unity.h"
int GlobalExpectCount;
int GlobalVerifyOrder;
char* GlobalOrderError;
/*=======External Functions This Runner Calls=====*/
extern void setUp(void);
extern void tearDown(void);
extern void test_generateID();
/*=======Mock Management=====*/
static void CMock_Init(void)
{
GlobalExpectCount = 0;
GlobalVerifyOrder = 0;
GlobalOrderError = NULL;
}
static void CMock_Verify(void)
{
}
static void CMock_Destroy(void)
{
}
/*=======Test Reset Options=====*/
void resetTest(void);
void resetTest(void)
{
tearDown();
CMock_Verify();
CMock_Destroy();
CMock_Init();
setUp();
}
void verifyTest(void);
void verifyTest(void)
{
CMock_Verify();
}
/*=======Test Runner Used To Run Each Test=====*/
static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE line_num)
{
Unity.CurrentTestName = name;
Unity.CurrentTestLineNumber = line_num;
#ifdef UNITY_USE_COMMAND_LINE_ARGS
if (!UnityTestMatches())
return;
#endif
Unity.NumberOfTests++;
UNITY_CLR_DETAILS();
UNITY_EXEC_TIME_START();
CMock_Init();
if (TEST_PROTECT())
{
setUp();
func();
}
if (TEST_PROTECT())
{
tearDown();
CMock_Verify();
}
CMock_Destroy();
UNITY_EXEC_TIME_STOP();
UnityConcludeTest();
}
/*=======MAIN=====*/
int main(void)
{
UnityBegin("test_CreateCustomer.c");
run_test(test_generateID, "test_generateID", 8);
return UnityEnd();
}

2
tests/project.yml

@ -34,7 +34,7 @@
- +:test/**
- -:test/support
:source:
- /home/julius/Documents/Studium/Informatik/1. Semester/ProgMeth/Bankmanagement/bankmanagement-system/src/**
- ../src/**
:support:
- test/support
:libraries: []

7
tests/test/test_main.c → tests/test/test_CreateCustomer.c

@ -1,10 +1,12 @@
#include "unity.h"
#include <unity.h>
#include <limits.h>
#include "CreateCustomer.h"
void setUp(){}
void tearDown(){}
void test_generateID(){
srand(time(0));
const int test_values = USHRT_MAX;
/*initialize blocks by calling generateID()*/
@ -15,6 +17,7 @@ void test_generateID(){
printf("%d\n", *(numbers+i));
}
/*assertions, range checking*/
int delta = 5000000, expected = 5000000;
for(int i=0;i<test_values;++i)
{
Loading…
Cancel
Save