diff --git a/.gitignore b/.gitignore index cb50d2d..a6db308 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,4 @@ dkms.conf main -*result.txt \ No newline at end of file +*results.txt \ No newline at end of file diff --git a/MMS24-25.c b/MMS24-25.c index 1f08442..93770d0 100644 --- a/MMS24-25.c +++ b/MMS24-25.c @@ -24,30 +24,41 @@ #define NULL 0 #endif -void _error(char* fmt,...) { - printf("<\x1B[31;1m ERROR \x1B[0m: \x1B[34m'"); +void _error(char* fmt, ...) { + fprintf(stderr, "<\x1B[31;1m ERROR \x1B[0m: \x1B[34m'"); va_list args; va_start(args, fmt); - printf(fmt, args); + vfprintf(stderr, fmt, args); va_end(args); - printf("'\x1B[0m >\n"); + fprintf(stderr, "'\x1B[0m >\n"); +#ifndef _TESTS_NONSTOP exit(-1); +#endif } -void _debug(char* fmt,...) { - printf("[\x1B[31;1m DEBUG \x1B[0m] \x1B[34m'"); +void _debug(char* fmt, ...) { + fprintf(stderr, "[\x1B[31;1m DEBUG \x1B[0m] \x1B[34m'"); va_list args; va_start(args, fmt); - printf(fmt, args); + vfprintf(stderr, fmt, args); va_end(args); - printf("'\x1B[0m\n"); + fprintf(stderr, "'\x1B[0m\n"); +} - exit(-1); +void _warn(char* fmt, ...) { + fprintf(stderr, "[\x1B[33;1m WARN \x1B[0m] \x1B[34m'"); + + va_list args; + va_start(args, fmt); + vfprintf(stderr, fmt, args); + va_end(args); + + fprintf(stderr, "'\x1B[0m\n"); } double interpolateLine( @@ -102,9 +113,22 @@ double *generateSineValues( ) { /* Generate an array of `iNumValues` double value, so that the values * represent the Y-coordinates of a sine curve of which one full period - * occupies `iNumSamplesPerPeriod` values + * occupies `iNumSamplesPerPeriod` values. */ + if (iNumSamplesPerPeriod == 0) + _error("*generateSineValues: iNumSamplesPerPeriod must be non-0!"); + + if (iNumSamplesPerPeriod < 0) + _warn("*generateSineValues: iNumSamplesPerPeriod is less than 0!"); + + if (iNumValues < 0) + _error("*generateSineValues: iNumValues must be equal to or greater than 0!"); + + if (iNumValues == 0) + _warn("*generateSineValues: iNumValues is 0!"); + + // Initialize the output array double* sineArray = NULL; sineArray = (double*) malloc(sizeof(double) * iNumValues); @@ -120,9 +144,7 @@ double *generateSineValues( } void writeDoubleArray(double *pdOut, int iLen, char *pcOutName) { - /* Write a list of double values to a file - */ - + // Write a list of double values to a file FILE* datei = fopen(pcOutName, "w"); if (datei == NULL) _error("writeDoubleArray: Error while opening file '%s'.\n", pcOutName); diff --git a/Makefile b/Makefile index b36eebb..1b5c3d8 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC=gcc SOURCE_FILE=MMS24-25.c -OPTS=-lm +OPTS=-lm -D _TESTS_NONSTOP all: clean tests run diff --git a/tests b/tests deleted file mode 100755 index 0b0af51..0000000 Binary files a/tests and /dev/null differ diff --git a/tests.c b/tests.c index f45de54..d7f0fca 100644 --- a/tests.c +++ b/tests.c @@ -9,44 +9,44 @@ #include void info(char* fmt,...) { - printf("[\x1B[37;1m INFO \x1B[0m]\t\x1B[34m'"); + fprintf(stderr, "[\x1B[37;1m INFO \x1B[0m] \x1B[34m'"); va_list args; va_start(args, fmt); - vprintf(fmt, args); + vfprintf(stderr, fmt, args); va_end(args); - printf("'\x1B[0m\n"); + fprintf(stderr, "'\x1B[0m\n"); } void success(char* fmt,...) { - printf("[\x1B[32;1m SUCCESS \x1B[0m]\t\x1B[34m'"); + fprintf(stderr, "[\x1B[32;1m PASS \x1B[0m] \x1B[34m'"); va_list args; va_start(args, fmt); - vprintf(fmt, args); + vfprintf(stderr, fmt, args); va_end(args); - printf("'\x1B[0m\n"); + fprintf(stderr, "'\x1B[0m\n"); } void error(const char* fmt, ...) { va_list args; - printf("<\x1B[31;1m ERROR \x1B[0m: \x1B[34m'"); + fprintf(stderr, "<\x1B[31;1m ERROR \x1B[0m: \x1B[34m'"); va_start(args, fmt); - vprintf(fmt, args); + vfprintf(stderr, fmt, args); va_end(args); - printf("'\x1B[0m >\n"); + fprintf(stderr, "'\x1B[0m >\n"); exit(-1); } void testInterpolation() { - info("testInterpolation();"); + info("testInterpolation"); - double dRangeMin = -10; - double dRangeMax = 10; - double dRangeStep = 0.5; + double dRangeMin = -3; + double dRangeMax = 3; + double dRangeStep = 0.33; for (double dX1=dRangeMin;dX1