1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <check.h>
#include <math.h>
#include <stdlib.h>
#include "rtfilter.h"
#include "test-common.h"
static inline
void create_random_signal(float * signal, int nch, int ns)
{
int i;
for (i = 0; i < ns * nch; i++)
signal[i] = (float) rand();
}
void smoke_test(struct rtf_filter * f, int nch, int ns)
{
int i;
float * in, * out;
ck_assert(f != NULL);
in = malloc(ns * nch * sizeof(*in));
out = malloc(ns * nch * sizeof(*out));
create_random_signal(in, nch, ns);
fill_signal(out, nch, ns, NAN);
rtf_filter(f, in, out, ns);
/* Smoke test:
* - no check on output values.
* - only ensure they are valid numbers */
for (i = 0; i < ns * nch; i++)
ck_assert(isfinite(out[i]));
free(out);
free(in);
}
void flat_test(struct rtf_filter * f, int nch, int ns)
{
int i;
float * in, * out;
ck_assert(f != NULL);
in = malloc(ns * nch * sizeof(*in));
out = malloc(ns * nch * sizeof(*out));
fill_signal(in, nch, ns, 0.f);
fill_signal(out, nch, ns, NAN);
rtf_filter(f, in, out, ns);
/* should return 0 on flat input */
for (i = 0; i < ns * nch; i++)
ck_assert(out[i] == 0.f);
free(out);
free(in);
}
|