diff --git a/MMS24-25.c b/MMS24-25.c index d9bcc81..1bf87c8 100644 --- a/MMS24-25.c +++ b/MMS24-25.c @@ -249,7 +249,7 @@ void rescaleDoubleArray( } /* - * Generate an array of `iNumValues` double value, so that the values + * Generate an array of `iNumValues` double values, so that the values * represent the Y-coordinates of a sine curve of which one full period * occupies `iNumSamplesPerPeriod` values. */ @@ -330,7 +330,7 @@ void writeDoubleArray(double *pdOut, int iLen, char *pcOutName) { _error("writeDoubleArray: Error while opening file '%s'.", pcOutName); if (iLen == 0) - _warn("writeDoubleArray: iLen is 0."); + _warn("writeDoubleArray: iLen is 0."); if (pdOut == NULL && iLen != 0) /* @@ -476,7 +476,7 @@ MMSignal *createSignalFromSignal(MMSignal *pmmsIn) { } } else { if (pmmsIn->iNumValues != 0) - _error("createSignalFromSignal: pmmsIn->pdValues is NULL while pmmsIn->iNumValues is not %d", pmmsIn->iNumValues); + _error("createSignalFromSignal: pmmsIn->pdValues is NULL while pmmsIn->iNumValues is not %d", pmmsIn->iNumValues); _warn("createSignalFromSignal: pmmsIn->pdValues is NULL"); signal->pdValues = NULL; @@ -895,8 +895,8 @@ Histogram *initHistogram(double *pdIn, int iLen, int iNumBins) { if (iNumBins == 0) _error("initHistogram: iNumBins must be non-0"); - if (iLen == 0) - _warn("initHistogram: iLen is 0"); + /*if (iLen == 0) // FIXME: This should be an error in the final version + _error("initHistogram: iLen is 0"); histogram->dIntervalMin = pdIn[0]; histogram->dIntervalMax = pdIn[0]; @@ -905,7 +905,12 @@ Histogram *initHistogram(double *pdIn, int iLen, int iNumBins) { histogram->dIntervalMin = pdIn[i]; if (pdIn[i] > histogram->dIntervalMax) histogram->dIntervalMax = pdIn[i]; - } + }*/ + + int minPos, maxPos; + getMinMaxPos(pdIn, iLen, &minPos, &maxPos); + histogram->dIntervalMin = pdIn[minPos]; + histogram->dIntervalMax = pdIn[maxPos]; #ifdef _DEBUG _debug("initHistogram: histogram->dIntervalMin = %lf", histogram->dIntervalMin); @@ -922,6 +927,7 @@ Histogram *initHistogram(double *pdIn, int iLen, int iNumBins) { if (histogram->dBinWidth == 0) histogram->dBinWidth = 1; + histogram->pdBinValues = NULL; // FIXME: This should be added in the final version histogram->pdBinValues = (double*) malloc(sizeof(double) *iNumBins); if (histogram->pdBinValues == NULL) _mem_error("initHistogram: Failed to allocate memory for histogram->pdBinValues"); @@ -997,7 +1003,8 @@ MMSignal *convoluteSignals(MMSignal *pmmsInA, MMSignal *pmmsInB) { // Calculate output length int iOutLen = pmmsInA->iNumValues + pmmsInB->iNumValues - 1; - double *pdOut = (double*) malloc(sizeof(double) *iOutLen); + double *pdOut = NULL; // FIXME: This should be added in the final version + pdOut = (double*) malloc(sizeof(double) *iOutLen); if (pdOut == NULL) _mem_error("convoluteSignals: Failed to allocate memory for pdOut"); diff --git a/MMS24-25_BEIMG_CAM_HORNB.zip b/MMS24-25_BEIMG_CAM_HORNB.zip new file mode 100644 index 0000000..67f5251 Binary files /dev/null and b/MMS24-25_BEIMG_CAM_HORNB.zip differ diff --git a/Makefile b/Makefile index c14a28a..bf8468c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC=gcc SOURCE_FILE=MMS24-25.c -OPTS=-lm -D _DEBUG_ +OPTS=-lm all: clean tests run diff --git a/err.txt b/err.txt new file mode 100644 index 0000000..50696ef --- /dev/null +++ b/err.txt @@ -0,0 +1,4 @@ +[ WARN ] 'Test!' +[ WARN ] 'Test!' +[ WARN ] 'Test!' +[ WARN ] 'Test!' diff --git a/result.txt b/result.txt new file mode 100644 index 0000000..0786535 --- /dev/null +++ b/result.txt @@ -0,0 +1,4 @@ +6.000000 +7.000000 +8.000000 +9.000000 diff --git a/testInterpolation b/testInterpolation new file mode 100755 index 0000000..f6dcf2c Binary files /dev/null and b/testInterpolation differ diff --git a/testInterpolation.c b/testInterpolation.c new file mode 100644 index 0000000..389bd3a --- /dev/null +++ b/testInterpolation.c @@ -0,0 +1,26 @@ +#include "MMS24-25.h" +#include +#include + +int main (int iArgC, char** ppcArgV){ + int iRes = -1; + + if (iArgC != 6){ + printf("Number of Arguments != 6\n"); + printf("Usage testInterpolation \n"); + exit(iRes); + }; + + double dX1 = atof(ppcArgV[1]); + double dY1 = atof(ppcArgV[2]); + double dX2 = atof(ppcArgV[3]); + double dY2 = atof(ppcArgV[4]); + double dX = atof(ppcArgV[5]); + + for(int i=0; i<4; i++){ + double dRes = interpolateLine(dX1, dY1, dX2, dY2, dX+(double)i); + printf ("%f\n",dRes); + } + + return iRes; +} diff --git a/tests.c b/tests.c index 1a271e2..9ad5137 100644 --- a/tests.c +++ b/tests.c @@ -496,6 +496,182 @@ void testCalcExtrema() { success("testCalcExtrema"); } +void testInitMMSignalFeatures() { + /* + * Test for Signals of multiple lengths including edge cases. + */ + + info("testInitMMSignalFeatures"); + + // Test for 0 values + info("Test for 0 values"); + MMSignal *signal = createSignalWithDefault(0, 0); + initMMSignalFeatures(signal); + if (signal->dArea != 0) { + error("Failed to calculate the correct area: %lf != 0", signal->dArea); + } + if (signal->dMean != 0) { + error("Failed to calculate the correct mean: %lf != 0", signal->dMean); + } + if (signal->dStdDev != 0) { + error("Failed to calculate the correct standard deviation: %lf != 0", signal->dStdDev); + } + if (signal->dMedian != 0) { + error("Failed to calculate the correct median: %lf != 0", signal->dMedian); + } + if (signal->pexExtrema->iGlobalMinPos != 0) { + error("Failed to calculate the correct global minimum position: %d != 0", signal->pexExtrema->iGlobalMinPos); + } + if (signal->pexExtrema->iGlobalMaxPos != 0) { + error("Failed to calculate the correct global maximum position: %d != 0", signal->pexExtrema->iGlobalMaxPos); + } + if (signal->pexExtrema->pexLocalMax->iNumLocalExtrema != 0) { + error("Failed to calculate the correct number of local maxima: %d != 0", signal->pexExtrema->pexLocalMax->iNumLocalExtrema); + } + deleteSignal(signal); + + // List of 1 to 10 + double pdValuesL[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + signal = createSignalFromDoubleArray(10, pdValuesL); + initMMSignalFeatures(signal); + if (signal->dArea != 55) { + error("Failed to calculate the correct area: %lf != 55", signal->dArea); + } + if (signal->dMean != 5.5) { + error("Failed to calculate the correct mean: %lf != 5.5", signal->dMean); + } + if (round(signal->dStdDev*1e6) != 2.872281e6) { + error("Failed to calculate the correct standard deviation: %lf != 2.872281", signal->dStdDev); + } + if (signal->dMedian != 5.5) { + error("Failed to calculate the correct median: %lf != 5.5", signal->dMedian); + } + if (signal->pexExtrema->iGlobalMinPos != 0) { + error("Failed to calculate the correct global minimum position: %d != 0", signal->pexExtrema->iGlobalMinPos); + } + if (signal->pexExtrema->iGlobalMaxPos != 9) { + error("Failed to calculate the correct global maximum position: %d != 9", signal->pexExtrema->iGlobalMaxPos); + } + if (signal->pexExtrema->pexLocalMax->iNumLocalExtrema != 0) { + error("Failed to calculate the correct number of local maxima: %d != 1", signal->pexExtrema->pexLocalMax->iNumLocalExtrema); + } + deleteSignal(signal); + + + // Test for 1 value + info("Test for 1 value"); + signal = createSignalWithDefault(1, 1); + initMMSignalFeatures(signal); + if (signal->dArea != 1) { + error("Failed to calculate the correct area: %lf != 1", signal->dArea); + } + if (signal->dMean != 1) { + error("Failed to calculate the correct mean: %lf != 1", signal->dMean); + } + if (signal->dStdDev != 0) { + error("Failed to calculate the correct standard deviation: %lf != 0", signal->dStdDev); + } + if (signal->dMedian != 1) { + error("Failed to calculate the correct median: %lf != 1", signal->dMedian); + } + if (signal->pexExtrema->iGlobalMinPos != 0) { + error("Failed to calculate the correct global minimum position: %d != 0", signal->pexExtrema->iGlobalMinPos); + } + if (signal->pexExtrema->iGlobalMaxPos != 0) { + error("Failed to calculate the correct global maximum position: %d != 0", signal->pexExtrema->iGlobalMaxPos); + } + if (signal->pexExtrema->pexLocalMax->iNumLocalExtrema != 0) { + error("Failed to calculate the correct number of local maxima: %d != 1", signal->pexExtrema->pexLocalMax->iNumLocalExtrema); + } + deleteSignal(signal); + + // Test for 2 values + info("testInitMMSignalFeatures: 2 values"); + double pdValuesT[] = {1, 1}; + signal = createSignalFromDoubleArray(2, pdValuesT); + initMMSignalFeatures(signal); + if (signal->dArea != 2) { + error("Failed to calculate the correct area: %lf != 2", signal->dArea); + } + if (signal->dMean != 1) { + error("Failed to calculate the correct mean: %lf != 1", signal->dMean); + } + if (signal->dStdDev != 0) { + error("Failed to calculate the correct standard deviation: %lf != 0", signal->dStdDev); + } + if (signal->dMedian != 1) { + error("Failed to calculate the correct median: %lf != 1", signal->dMedian); + } + if (signal->pexExtrema->iGlobalMinPos != 0) { + error("Failed to calculate the correct global minimum position: %d != 0", signal->pexExtrema->iGlobalMinPos); + } + if (signal->pexExtrema->iGlobalMaxPos != 0) { + error("Failed to calculate the correct global maximum position: %d != 0", signal->pexExtrema->iGlobalMaxPos); + } + if (signal->pexExtrema->pexLocalMax->iNumLocalExtrema != 0) { + error("Failed to calculate the correct number of local maxima: %d != 0", signal->pexExtrema->pexLocalMax->iNumLocalExtrema); + } + deleteSignal(signal); + + // Test for 3 values with local maximum + info("testInitMMSignalFeatures: 3 values with local maximum"); + double pdValues[] = {1, 2, 1}; + signal = createSignalFromDoubleArray(3, pdValues); + initMMSignalFeatures(signal); + if (signal->dArea != 4) { + error("Failed to calculate the correct area: %lf != 4", signal->dArea); + } + if (signal->dMean != 4.0/3.0) { + error("Failed to calculate the correct mean: %lf != 4/3", signal->dMean); + } + if (round(signal->dStdDev*1e6) != 0.471405e6) { + error("Failed to calculate the correct standard deviation: %lf != 0.471405", signal->dStdDev); + } + if (signal->dMedian != 1) { + error("Failed to calculate the correct median: %lf != 1", signal->dMedian); + } + if (signal->pexExtrema->iGlobalMinPos != 0) { + error("Failed to calculate the correct global minimum position: %d != 2", signal->pexExtrema->iGlobalMinPos); + } + if (signal->pexExtrema->iGlobalMaxPos != 1) { + error("Failed to calculate the correct global maximum position: %d != 1", signal->pexExtrema->iGlobalMaxPos); + } + if (signal->pexExtrema->pexLocalMax->iNumLocalExtrema != 1) { + error("Failed to calculate the correct number of local maxima: %d != 1", signal->pexExtrema->pexLocalMax->iNumLocalExtrema); + } + deleteSignal(signal); + + // Test for 3 values with local minimum + info("testInitMMSignalFeatures: 3 values with local minimum"); + double pdValues2[] = {1, 0, 1}; + signal = createSignalFromDoubleArray(3, pdValues2); + initMMSignalFeatures(signal); + if (signal->dArea != 2) { + error("Failed to calculate the correct area: %lf != 2", signal->dArea); + } + if (signal->dMean != 2.0/3.0) { + error("Failed to calculate the correct mean: %lf != 2/3", signal->dMean); + } + if (round(signal->dStdDev*1e6) != 0.471405e6) { + error("Failed to calculate the correct standard deviation: %lf != 0.471405", signal->dStdDev); + } + if (signal->dMedian != 1) { + error("Failed to calculate the correct median: %lf != 1", signal->dMedian); + } + if (signal->pexExtrema->iGlobalMinPos != 1) { + error("Failed to calculate the correct global minimum position: %d != 1", signal->pexExtrema->iGlobalMinPos); + } + if (signal->pexExtrema->iGlobalMaxPos != 0) { + error("Failed to calculate the correct global maximum position: %d != 2", signal->pexExtrema->iGlobalMaxPos); + } + if (signal->pexExtrema->pexLocalMin->iNumLocalExtrema != 1) { + error("Failed to calculate the correct number of local minima: %d != 1", signal->pexExtrema->pexLocalMin->iNumLocalExtrema); + } + deleteSignal(signal); + + success("testInitMMSignalFeatures"); +} + int main (int iArgC, char** ppcArgV){ testInterpolation(); testSineAndReadWriteDoubleArray(); @@ -515,8 +691,7 @@ int main (int iArgC, char** ppcArgV){ testConvertPolar2Cart(); testApplyPascalConvForSeriesGT40(); testCalcExtrema(); - - initMMSignalFeatures(createSignal()); + testInitMMSignalFeatures(); return 0; }