Compare commits

..

No commits in common. "840d5b0c4fd732cc414d71f9d49a981b9cf1b80d" and "1b52f921966d463c816b13bccdd1adc6991b1d30" have entirely different histories.

5 changed files with 28 additions and 91 deletions

4
.gitignore vendored
View File

@ -54,6 +54,4 @@ dkms.conf
main
*results.txt
tests
*result.txt

View File

@ -24,41 +24,30 @@
#define NULL 0
#endif
void _error(char* fmt, ...) {
fprintf(stderr, "<\x1B[31;1m ERROR \x1B[0m: \x1B[34m'");
void _error(char* fmt,...) {
printf("<\x1B[31;1m ERROR \x1B[0m: \x1B[34m'");
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
printf(fmt, args);
va_end(args);
fprintf(stderr, "'\x1B[0m >\n");
printf("'\x1B[0m >\n");
#ifndef _TESTS_NONSTOP
exit(-1);
#endif
}
void _debug(char* fmt, ...) {
fprintf(stderr, "[\x1B[31;1m DEBUG \x1B[0m] \x1B[34m'");
void _debug(char* fmt,...) {
printf("[\x1B[31;1m DEBUG \x1B[0m] \x1B[34m'");
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
printf(fmt, args);
va_end(args);
fprintf(stderr, "'\x1B[0m\n");
}
printf("'\x1B[0m\n");
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");
exit(-1);
}
double interpolateLine(
@ -113,22 +102,9 @@ 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);
@ -144,7 +120,9 @@ 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);

View File

@ -1,6 +1,6 @@
CC=gcc
SOURCE_FILE=MMS24-25.c
OPTS=-lm -D _TESTS_NONSTOP
OPTS=-lm
all: clean tests run

BIN
tests Executable file

Binary file not shown.

65
tests.c
View File

@ -9,44 +9,44 @@
#include <math.h>
void info(char* fmt,...) {
fprintf(stderr, "[\x1B[37;1m INFO \x1B[0m] \x1B[34m'");
printf("[\x1B[37;1m INFO \x1B[0m]\t\x1B[34m'");
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
vprintf(fmt, args);
va_end(args);
fprintf(stderr, "'\x1B[0m\n");
printf("'\x1B[0m\n");
}
void success(char* fmt,...) {
fprintf(stderr, "[\x1B[32;1m PASS \x1B[0m] \x1B[34m'");
printf("[\x1B[32;1m SUCCESS \x1B[0m]\t\x1B[34m'");
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
vprintf(fmt, args);
va_end(args);
fprintf(stderr, "'\x1B[0m\n");
printf("'\x1B[0m\n");
}
void error(const char* fmt, ...) {
va_list args;
fprintf(stderr, "<\x1B[31;1m ERROR \x1B[0m: \x1B[34m'");
printf("<\x1B[31;1m ERROR \x1B[0m: \x1B[34m'");
va_start(args, fmt);
vfprintf(stderr, fmt, args);
vprintf(fmt, args);
va_end(args);
fprintf(stderr, "'\x1B[0m >\n");
printf("'\x1B[0m >\n");
exit(-1);
}
void testInterpolation() {
info("testInterpolation");
info("testInterpolation();");
double dRangeMin = -3;
double dRangeMax = 3;
double dRangeStep = 0.33;
double dRangeMin = -10;
double dRangeMax = 10;
double dRangeStep = 0.5;
for (double dX1=dRangeMin;dX1<dRangeMax;dX1+=dRangeStep) {
for (double dX2=dRangeMin;dX2<dRangeMax;dX2+=dRangeStep) {
@ -70,47 +70,8 @@ void testInterpolation() {
success("testInterpolation();");
}
void testSineAndWriteDoubleArraySingle(int nValues, int dPLen, double dAmp) {
info("Trying: %d, %d, %lf", nValues, dPLen, dAmp);
char* fileName = NULL;
fileName = malloc(100*sizeof(char));
if (fileName == NULL) {
error("Could not allocate Memory for `fileName`!");
}
sprintf(fileName, "sine_%d_%d_%lf.results.txt", nValues, dPLen, dAmp);
writeDoubleArray(
generateSineValues(
nValues,
dPLen,
dAmp
),
nValues,
fileName
);
info("use `plot \"%s\", \"%s\" with lines` to view.", fileName, fileName);
free(fileName);
}
void testSineAndWriteDoubleArray() {
info("testSineAndWriteDoubleArray");
testSineAndWriteDoubleArraySingle(1000, 300, 1);
testSineAndWriteDoubleArraySingle(10, 10, 0.5);
testSineAndWriteDoubleArraySingle(10, -10, 0.5);
testSineAndWriteDoubleArraySingle(10, 10, 0);
success("testSineAndWriteDoubleArray");
}
int main (int iArgC, char** ppcArgV){
testInterpolation();
testSineAndWriteDoubleArray();
return 0;
}