Browse Source

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

remotes/origin/beta
fdai7057 2 years ago
committed by fdai7207
parent
commit
f0ad90dbd1
  1. 19
      src/CreateCustomer.c
  2. 7
      tests/test_CreateCustomer.c

19
src/CreateCustomer.c

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

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

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