summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/auxiliaryFunctions/find/cfinda.c11
-rw-r--r--src/auxiliaryFunctions/find/dfinda.c11
-rw-r--r--src/auxiliaryFunctions/find/sfinda.c11
-rw-r--r--src/auxiliaryFunctions/find/testFind.c171
-rw-r--r--src/auxiliaryFunctions/find/zfinda.c13
-rw-r--r--src/auxiliaryFunctions/includes/find.h8
6 files changed, 148 insertions, 77 deletions
diff --git a/src/auxiliaryFunctions/find/cfinda.c b/src/auxiliaryFunctions/find/cfinda.c
index 75a621c3..8dcf6c1f 100644
--- a/src/auxiliaryFunctions/find/cfinda.c
+++ b/src/auxiliaryFunctions/find/cfinda.c
@@ -12,12 +12,17 @@
#include "find.h"
-int cfinda(floatComplex* z, int size) {
+float *cfinda(floatComplex* z, int size) {
int i = 0;
+ int indiceOut = 0;
+ float* out=NULL;
+
for (i = 0; i < size ; ++i) {
if (creals(z[i]) != 0 || cimags(z[i]) != 0) {
- return i;
+ out = realloc(out, (uint)(indiceOut+1)*sizeof(float));
+ out[indiceOut] = (float)i;
+ indiceOut++;
}
}
- return NOT_FOUND;
+ return out;
}
diff --git a/src/auxiliaryFunctions/find/dfinda.c b/src/auxiliaryFunctions/find/dfinda.c
index b347d771..efbda20e 100644
--- a/src/auxiliaryFunctions/find/dfinda.c
+++ b/src/auxiliaryFunctions/find/dfinda.c
@@ -12,12 +12,17 @@
#include "find.h"
-int dfinda(double* x, int size) {
+double *dfinda(double* x, int size) {
int i = 0;
+ int indiceOut = 0;
+ double* out=NULL;
+
for (i = 0; i < size ; ++i) {
if (x[i] != 0) {
- return i;
+ out = realloc(out, (uint)(indiceOut+1)*sizeof(double));
+ out[indiceOut] = (double)i;
+ indiceOut++;
}
}
- return NOT_FOUND;
+ return out;
}
diff --git a/src/auxiliaryFunctions/find/sfinda.c b/src/auxiliaryFunctions/find/sfinda.c
index f038c9c9..74fd3cf8 100644
--- a/src/auxiliaryFunctions/find/sfinda.c
+++ b/src/auxiliaryFunctions/find/sfinda.c
@@ -12,13 +12,18 @@
#include "find.h"
-int sfinda(float* x, int size) {
+float* sfinda(float* x, int size) {
int i = 0;
+ int indiceOut = 0;
+ float* out=NULL;
+
for (i = 0; i < size ; ++i) {
if (x[i] != 0) {
- return i;
+ out = realloc(out, (uint)(indiceOut+1)*sizeof(float));
+ out[indiceOut] = (float)i;
+ indiceOut++;
}
}
- return NOT_FOUND;
+ return out;
}
diff --git a/src/auxiliaryFunctions/find/testFind.c b/src/auxiliaryFunctions/find/testFind.c
index f191b368..95b1b17c 100644
--- a/src/auxiliaryFunctions/find/testFind.c
+++ b/src/auxiliaryFunctions/find/testFind.c
@@ -13,109 +13,160 @@
#include "testFind.h"
int sfindaTest() {
- int result = 0;
+ int result = 0, i = 0;
float goodArray[5] = {0.,2.,3.,5.,10.};
float badArray[5] = {0.,0.,0.,0.,0.};
+ float res[4] = {1.,2.,3.,4.};
+ float *outGood = NULL, *outBad = NULL;
printf(">> Floats \n");
- if (sfinda(goodArray, 5) == NOT_FOUND) {
+ outGood = sfinda(goodArray, 5);
+ outBad = sfinda(badArray, 5);
+
+ for (i=0;i<4;i++){
+ if ( outGood[i] != res[i]) {
printf("ERROR ! : Test Failed (non empty array)\n");
result = ERROR;
+ }
+ else
+ printf("%f ",outGood[i]);
}
- assert(sfinda(goodArray, 5) != NOT_FOUND);
- assert(sfinda(goodArray, 5) == 1);
- if (sfinda(badArray, 5) != NOT_FOUND) {
+
+ printf("\n");
+
+ if (outBad!=NULL) {
printf("ERROR ! : Test Failed (empty array)\n");
result = ERROR;
}
- assert(sfinda(badArray, 5) == NOT_FOUND);
+ else
+ printf("%f ",outGood[i]);
+
+ printf("\n");
return result;
}
int dfindaTest() {
+ int result = 0, i = 0;
double goodArray[5] = {0.,2.,3.,5.,10.};
double badArray[5] = {0.,0.,0.,0.,0.};
+ double res[4] = {1.,2.,3.,4.};
+ double *outGood = NULL, *outBad = NULL;
- printf(">> Doubles \n");
- assert(dfinda(goodArray, 5) != NOT_FOUND);
- assert(dfinda(goodArray, 5) == 1);
- if (dfinda(goodArray, 5) == NOT_FOUND) {
+ printf(">> Double \n");
+ outGood = dfinda(goodArray, 5);
+ outBad = dfinda(badArray, 5);
+
+ for (i=0;i<4;i++){
+ if ( outGood[i] != res[i]) {
printf("ERROR ! : Test Failed (non empty array)\n");
- return ERROR;
+ result = ERROR;
+ }
+ else
+ printf("%f ",outGood[i]);
}
- assert(dfinda(badArray, 5) == NOT_FOUND);
- if (dfinda(badArray, 5) != NOT_FOUND) {
+
+ printf("\n");
+
+ if (outBad!=NULL) {
printf("ERROR ! : Test Failed (empty array)\n");
- return ERROR;
+ result = ERROR;
}
- return 0;
+ else
+ printf("%f ",outGood[i]);
+
+ printf("\n");
+ return result;
}
int cfindaTest() {
- int result = 0;
- floatComplex goodArray[5];
- floatComplex badArray[5];
- /* Good values in goodArray */
- goodArray[0] = FloatComplex(0., 0.);
- goodArray[1] = FloatComplex(0., 2.);
- goodArray[2] = FloatComplex(3., 50.);
- goodArray[3] = FloatComplex(5., 10.);
- goodArray[4] = FloatComplex(10., -10.);
- /* Bad values in badArray */
- badArray[0] = FloatComplex(0., 0.);
- badArray[1] = FloatComplex(0., 0.);
- badArray[2] = FloatComplex(0., 0.);
- badArray[3] = FloatComplex(0., 0.);
+ int result = 0, i = 0;
+ floatComplex goodArray[5];
+ floatComplex badArray[5];
+ float res[4] = {1.,2.,3.,4.};
+ float *outGood = NULL, *outBad = NULL;
+
+ /* Good values in goodArray */
+ goodArray[0] = FloatComplex(0., 0.);
+ goodArray[1] = FloatComplex(0., 2.);
+ goodArray[2] = FloatComplex(3., 50.);
+ goodArray[3] = FloatComplex(5., 10.);
+ goodArray[4] = FloatComplex(10., -10.);
+ /* Bad values in badArray */
+ badArray[0] = FloatComplex(0., 0.);
+ badArray[1] = FloatComplex(0., 0.);
+ badArray[2] = FloatComplex(0., 0.);
+ badArray[3] = FloatComplex(0., 0.);
badArray[4] = FloatComplex(0., 0.);
-
+
printf(">> Float Complex \n");
- if (cfinda(goodArray, 5) == NOT_FOUND) {
+ outGood = cfinda(goodArray, 5);
+ outBad = cfinda(badArray, 5);
+
+ for (i=0;i<4;i++){
+ if ( outGood[i] != res[i]) {
printf("ERROR ! : Test Failed (non empty array)\n");
result = ERROR;
+ }
+ else
+ printf("%f ",outGood[i]);
}
- assert(cfinda(goodArray, 5) != NOT_FOUND);
- assert(cfinda(goodArray, 5) == 1);
- if (cfinda(badArray, 5) != NOT_FOUND) {
+
+ printf("\n");
+
+ if (outBad!=NULL) {
printf("ERROR ! : Test Failed (empty array)\n");
result = ERROR;
}
- assert(cfinda(badArray, 5) == NOT_FOUND);
+ else
+ printf("%f ",outGood[i]);
+
+ printf("\n");
return result;
}
int zfindaTest() {
- int result = 0;
- doubleComplex goodArray[5];
- doubleComplex badArray[5];
- /* Good values in goodArray. */
- goodArray[0] = DoubleComplex(0., 0.);
- goodArray[1] = DoubleComplex(0., 2.);
- goodArray[2] = DoubleComplex(3., 50.);
- goodArray[3] = DoubleComplex(5., 10.);
- goodArray[4] = DoubleComplex(10., -10.);
- /* Bad values in badArray */
- badArray[0] = DoubleComplex(0., 0.);
- badArray[1] = DoubleComplex(0., 0.);
- badArray[2] = DoubleComplex(0., 0.);
- badArray[3] = DoubleComplex(0., 0.);
+ int result = 0, i = 0;
+ doubleComplex goodArray[5];
+ doubleComplex badArray[5];
+ double res[4] = {1.,2.,3.,4.};
+ double *outGood = NULL, *outBad = NULL;
+ /* Good values in goodArray */
+ goodArray[0] = DoubleComplex(0., 0.);
+ goodArray[1] = DoubleComplex(0., 2.);
+ goodArray[2] = DoubleComplex(3., 50.);
+ goodArray[3] = DoubleComplex(5., 10.);
+ goodArray[4] = DoubleComplex(10., -10.);
+ /* Bad values in badArray */
+ badArray[0] = DoubleComplex(0., 0.);
+ badArray[1] = DoubleComplex(0., 0.);
+ badArray[2] = DoubleComplex(0., 0.);
+ badArray[3] = DoubleComplex(0., 0.);
badArray[4] = DoubleComplex(0., 0.);
-
- printf(">> Double Complex \n");
- if (zfinda(goodArray, 5) == NOT_FOUND) {
+
+
+ printf(">> Float Complex \n");
+ outGood = zfinda(goodArray, 5);
+ outBad = zfinda(badArray, 5);
+
+ for (i=0;i<4;i++){
+ if ( outGood[i] != res[i]) {
printf("ERROR ! : Test Failed (non empty array)\n");
result = ERROR;
+ }
+ else
+ printf("%f ",outGood[i]);
}
- assert(zfinda(goodArray, 5) != NOT_FOUND);
- if (zfinda(goodArray, 5) != 1) {
- printf("ERROR ! : Test Failed (Element found in place %d instead of 1)\n", zfinda(goodArray, 5));
- result = ERROR;
- }
- assert(zfinda(goodArray, 5) == 1);
- if (zfinda(badArray, 5) != NOT_FOUND) {
+
+ printf("\n");
+
+ if (outBad!=NULL) {
printf("ERROR ! : Test Failed (empty array)\n");
result = ERROR;
}
- assert(zfinda(badArray, 5) == NOT_FOUND);
+ else
+ printf("%f ",outGood[i]);
+
+ printf("\n");
return result;
}
diff --git a/src/auxiliaryFunctions/find/zfinda.c b/src/auxiliaryFunctions/find/zfinda.c
index e01d42ca..18c87a25 100644
--- a/src/auxiliaryFunctions/find/zfinda.c
+++ b/src/auxiliaryFunctions/find/zfinda.c
@@ -12,12 +12,17 @@
#include "find.h"
-int zfinda(doubleComplex* z, int size) {
- int i = 0;
+double *zfinda(doubleComplex* z, int size) {
+ int i = 0;
+ int indiceOut = 0;
+ double* out=NULL;
+
for (i = 0; i < size ; ++i) {
if (zreals(z[i]) != 0 || zimags(z[i]) != 0) {
- return i;
+ out = realloc(out, (uint)(indiceOut+1)*sizeof(double));
+ out[indiceOut] = (double)i;
+ indiceOut++;
}
}
- return NOT_FOUND;
+ return out;
}
diff --git a/src/auxiliaryFunctions/includes/find.h b/src/auxiliaryFunctions/includes/find.h
index 2389cb7d..73682bac 100644
--- a/src/auxiliaryFunctions/includes/find.h
+++ b/src/auxiliaryFunctions/includes/find.h
@@ -20,20 +20,20 @@
/*
** \brief Float Find function
*/
-int sfinda(float* x, int size);
+float* sfinda(float* x, int size);
/*
** \brief Double Find function
*/
-int dfinda(double*x, int size);
+double* dfinda(double*x, int size);
/*
** \brief Float Complex Find function
*/
-int cfinda(floatComplex* z, int size);
+float* cfinda(floatComplex* z, int size);
/*
** \brief Double Complex Find function
*/
-int zfinda(doubleComplex* z, int size);
+double* zfinda(doubleComplex* z, int size);
#endif /* !__FIND_H__ */