Post-Submission Changes
This commit is contained in:
parent
7476f174a3
commit
253d191f13
17
MMS24-25.c
17
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.
|
||||
*/
|
||||
@ -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");
|
||||
|
||||
|
||||
BIN
MMS24-25_BEIMG_CAM_HORNB.zip
Normal file
BIN
MMS24-25_BEIMG_CAM_HORNB.zip
Normal file
Binary file not shown.
2
Makefile
2
Makefile
@ -1,6 +1,6 @@
|
||||
CC=gcc
|
||||
SOURCE_FILE=MMS24-25.c
|
||||
OPTS=-lm -D _DEBUG_
|
||||
OPTS=-lm
|
||||
|
||||
all: clean tests run
|
||||
|
||||
|
||||
4
err.txt
Normal file
4
err.txt
Normal file
@ -0,0 +1,4 @@
|
||||
[ [33;4;1mWARN[0m ] [34m'Test!'[0m
|
||||
[ [33;4;1mWARN[0m ] [34m'Test!'[0m
|
||||
[ [33;4;1mWARN[0m ] [34m'Test!'[0m
|
||||
[ [33;4;1mWARN[0m ] [34m'Test!'[0m
|
||||
4
result.txt
Normal file
4
result.txt
Normal file
@ -0,0 +1,4 @@
|
||||
6.000000
|
||||
7.000000
|
||||
8.000000
|
||||
9.000000
|
||||
BIN
testInterpolation
Executable file
BIN
testInterpolation
Executable file
Binary file not shown.
26
testInterpolation.c
Normal file
26
testInterpolation.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "MMS24-25.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main (int iArgC, char** ppcArgV){
|
||||
int iRes = -1;
|
||||
|
||||
if (iArgC != 6){
|
||||
printf("Number of Arguments != 6\n");
|
||||
printf("Usage testInterpolation <dX1> <dY1> <dX2> <dY2> <dX>\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;
|
||||
}
|
||||
179
tests.c
179
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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user