diff options
Diffstat (limited to 'src/test.c')
-rw-r--r-- | src/test.c | 69 |
1 files changed, 69 insertions, 0 deletions
@@ -24,6 +24,7 @@ #include <gsl/gsl_cdf.h> #include "sno.h" #include "quad.h" +#include "find_peaks.h" typedef int testFunction(char *err); @@ -1566,6 +1567,73 @@ err: return 1; } +int test_find_peaks_array(char *err) +{ + /* Tests the find_peaks_array() function. */ + size_t i; + double x[4] = {0,1,0,0}; + size_t imax[10], jmax[10], npeaks; + + find_peaks_array(x,2,2,imax,jmax,&npeaks,LEN(imax),0.1); + + if (npeaks != 1) { + sprintf(err, "number of peaks = %zu, but expected %i", npeaks, 1); + return 1; + } + + if (imax[0] != 0) { + sprintf(err, "imax[0] = %zu, but expected %i", imax[0], 0); + return 1; + } + + if (jmax[0] != 1) { + sprintf(err, "jmax[0] = %zu, but expected %i", jmax[0], 1); + return 1; + } + + double y[10][10] = { + {0,0,2,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {4,0,0,0,0,0,0,0,0,5}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,3,0,0,0,0,0,0,0}, + }; + + find_peaks_array(y,10,10,imax,jmax,&npeaks,LEN(imax),0.1); + + if (npeaks != 2) { + sprintf(err, "number of peaks = %zu, but expected %i", npeaks, 2); + return 1; + } + + if (imax[0] != 2) { + sprintf(err, "imax[0] = %zu, but expected %i", imax[0], 2); + return 1; + } + + if (jmax[0] != 9) { + sprintf(err, "jmax[0] = %zu, but expected %i", jmax[0], 9); + return 1; + } + + if (imax[1] != 9) { + sprintf(err, "imax[1] = %zu, but expected %i", imax[1], 9); + return 1; + } + + if (jmax[1] != 2) { + sprintf(err, "jmax[1] = %zu, but expected %i", jmax[1], 2); + return 1; + } + + return 0; +} + struct tests { testFunction *test; char *name; @@ -1606,6 +1674,7 @@ struct tests { {test_time_cdf, "test_time_cdf"}, {test_quad, "test_quad"}, {test_quad_noise, "test_quad_noise"}, + {test_find_peaks_array, "test_find_peaks_array"}, }; int main(int argc, char **argv) |