diff --git a/src/CustomerProperties.h b/src/CustomerProperties.h index 2bbab62..e2ba317 100644 --- a/src/CustomerProperties.h +++ b/src/CustomerProperties.h @@ -1,4 +1,5 @@ typedef struct Customer{ - char *ID, *forename, *surname, *password; + int ID; + char *forename,*surname,*password; float balance; }customer_t; diff --git a/src/StringManipulation.c b/src/StringManipulation.c new file mode 100644 index 0000000..7ac306e --- /dev/null +++ b/src/StringManipulation.c @@ -0,0 +1,68 @@ +#include "StringManipulation.h" +/*Code written by Julius Philipp Engel, fdai7057*/ + +char *stringConcatenation(char *string_1, char *string_2) +{ + int lengthStringOne = strlen(string_1); + int lengthStringTwo = strlen(string_2); + + if(lengthStringOne==0||lengthStringTwo==0){ + printf("Empty strings are not allowed. Aborting.\n"); + exit(-1); + //call error(); + } + + const int totalLength = lengthStringOne + lengthStringTwo + 1; + char *result = calloc(totalLength, sizeof(char)); + int i,j; + for(i=0,j=0;i0){ + ++len; + number /= 10; + } + char *str = calloc(len+1, sizeof(char)); + for(int i=0,j=len-1;i +#include + +void test_to_string() +{ + /*initializing test values*/ + char *result_1[] = {"0","1","2","3","4","5","6","7","8","9","10"}; + char *result_2[] = {"500","502","504","506","508","510","512","514","516","518"}; + char *result_3[] = {"1000","2000","3000","4000","5000","6000","7000","8000","9000","10000"}; + char *result_4[] = {"9999","8999","7999","6999","5999","4999","3999","2999","1999","999"}; + char *result_5[] = {"1000000","2000000","3000000","4000000","5000000","6000000","7000000", + "8000000","9000000","10000000"}; + + for(int i=0;i<=10;++i){ + TEST_ASSERT_EQUAL_STRING(result_1[i],to_string(i)); + } + + for(int i=0, j=500;i<10;++i,j+=2){ + TEST_ASSERT_EQUAL_STRING(result_2[i],to_string(j)); + } + + for(int i=0, j=1000;i<10;++i,j+=1000){ + TEST_ASSERT_EQUAL_STRING(result_3[i],to_string(j)); + } + + for(int i=0, j=9999;i<10;++i,j-=1000){ + TEST_ASSERT_EQUAL_STRING(result_4[i], to_string(j)); + } + for(int i=0, j=1000000;i<10;++i,j+=1000000){ + TEST_ASSERT_EQUAL_STRING(result_5[i],to_string(j)); + } + +} + + +void test_generateCheckString() +{ + /*test block 1*/ + int numbers_1[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25}; + char *strings_1[] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}; + char *result_1[] = {"0=a","1=b","2=c","3=d","4=e","5=f","6=g","7=h","8=i","9=j","10=k","11=l","12=m","13=n","14=o","15=p","16=q","17=r", "18=s","19=t","20=u","21=v","22=w","23=x","24=y","25=z"}; + for(int i=0;i<26;++i){ + TEST_ASSERT_EQUAL_STRING(result_1[i],generateCheckString(numbers_1[i],*(strings_1+i))); + } + /*test block 2*/ + int numbers_2[] = {0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025}; + char *strings_2[] = {"z","zy","zyx","zyxw","zyxwv","zyxwvu","zyxwvut","zyxwvuts","zyxwvutsr","zyxwvutsrq","zyxwvutsrqp", + "zyxwvutsrqpo","zyxwvutsrqpon","zyxwvutsrqponm","zyxwvutsrqponml","zyxwvutsrqponmlk", + "zyxwvutsrqponmlkj","zyxwvutsrqponmlkji","zyxwvutsrqponmlkjih","zyxwvutsrqponmlkjihg","zyxwvutsrqponmlkjihgf", + "zyxwvutsrqponmlkjihgfe","zyxwvutsrqponmlkjihgfed","zyxwvutsrqponmlkjihgfedc","zyxwvutsrqponmlkjihgfedcb", + "zyxwvutsrqponmlkjihgfedcba"}; + char *result_2[] = {"0=z","1=zy","1=zyx","2=zyxw","3=zyxwv","5=zyxwvu","8=zyxwvut","13=zyxwvuts","21=zyxwvutsr","34=zyxwvutsrq", + "55=zyxwvutsrqp","89=zyxwvutsrqpo","144=zyxwvutsrqpon","233=zyxwvutsrqponm","377=zyxwvutsrqponml", + "610=zyxwvutsrqponmlk","987=zyxwvutsrqponmlkj","1597=zyxwvutsrqponmlkji","2584=zyxwvutsrqponmlkjih", + "4181=zyxwvutsrqponmlkjihg","6765=zyxwvutsrqponmlkjihgf","10946=zyxwvutsrqponmlkjihgfe", + "17711=zyxwvutsrqponmlkjihgfed","28657=zyxwvutsrqponmlkjihgfedc","46368=zyxwvutsrqponmlkjihgfedcb", + "75025=zyxwvutsrqponmlkjihgfedcba"}; + for(int i=0;i<26;++i){ + TEST_ASSERT_EQUAL_STRING(result_2[i],generateCheckString(numbers_2[i],*(strings_2+i))); + } + /*test block 3*/ + srand(time(0)); + int random_number=0; + char *random_numbers_strings[20]; + int random_numbers[20]; + for(int i=0;i<20;++i){ + random_number = (rand() % 100) + 1; + random_numbers_strings[i] = to_string(random_number); + random_numbers[i] = random_number; + } + char *strings_3[] = {"tree","plant","tea","programming","assembler","unix","BSD","snow","mountain","table","wood","forest", "calculator","book","light","keyboard","old","paper","pencil","voltage"}; + char *result_3[20]; + for(int i=0;i<20;++i){ + random_numbers_strings[i] = strcat(random_numbers_strings[i],"="); + result_3[i] = strcat(random_numbers_strings[i],strings_3[i]); + printf("%s\n",result_3[i]); + } + for(int i=0;i<20;++i){ + TEST_ASSERT_EQUAL_STRING(result_3[i],generateCheckString(random_numbers[i],strings_3[i])); + } +}