change a_float to a_real
[liba.git] / test / mf.h
blobb69f57a3b914e09f65c17a8b78ad2562a2c90f35
1 #define MAIN(x) mf##x
2 #include "test.h"
3 #include "a/mf.h"
4 #include <string.h>
6 int main(int argc, char *argv[]) /* NOLINT(misc-definitions-in-headers) */
8 int i;
9 unsigned int e = A_MF_NUL;
10 a_real params[6] = {0, 0, 0, 0, 0, 0};
11 main_init(argc, argv, 1);
12 if (argc > 1)
14 if (strstr(argv[1], "gauss2.")) { e = A_MF_GAUSS2; }
15 else if (strstr(argv[1], "gauss.")) { e = A_MF_GAUSS; }
16 else if (strstr(argv[1], "gbell.")) { e = A_MF_GBELL; }
17 else if (strstr(argv[1], "dsig.")) { e = A_MF_DSIG; }
18 else if (strstr(argv[1], "psig.")) { e = A_MF_PSIG; }
19 else if (strstr(argv[1], "sig.")) { e = A_MF_SIG; }
20 else if (strstr(argv[1], "trap.")) { e = A_MF_TRAP; }
21 else if (strstr(argv[1], "tri.")) { e = A_MF_TRI; }
22 else if (strstr(argv[1], "lins.")) { e = A_MF_LINS; }
23 else if (strstr(argv[1], "linz.")) { e = A_MF_LINZ; }
24 else if (strstr(argv[1], "s.")) { e = A_MF_S; }
25 else if (strstr(argv[1], "z.")) { e = A_MF_Z; }
26 else if (strstr(argv[1], "pi.")) { e = A_MF_PI; }
28 for (i = 2; i < argc && i < 8; ++i)
30 params[i - 2] = strtonum(argv[i], A_NULL);
32 if (e != A_MF_NUL)
34 a_real delta = (params[1] - params[0]) / A_REAL_C(100.0);
35 for (i = 0; i < 100; ++i)
37 a_real x = params[0] + delta * a_real_c(i);
38 a_real y = a_mf(e, x, params + 2);
39 debug("%" A_REAL_PRI "g,%" A_REAL_PRI "g\n", x, y);
42 else
44 TEST_BUG(a_mf_gauss(0, 1, 0) >= 1);
45 TEST_BUG(a_mf_gauss2(0, 1, -1, +1, 1) >= 1);
46 TEST_BUG(a_mf_gbell(0, 2, 4, 0) >= 1);
47 TEST_BUG(a_mf_sig(0, 2, 0) >= 0.5);
48 TEST_BUG(a_mf_dsig(0, 5, -2, +5, +2) > 0.99);
49 TEST_BUG(a_mf_psig(0, 5, -2, -5, +2) > 0.99);
50 TEST_BUG(a_mf_trap(0, -2, -1, +1, 2) >= 1);
51 TEST_BUG(a_mf_tri(0, -1, 0, +1) >= 1);
52 TEST_BUG(a_mf_lins(0, -1, 0) >= 1);
53 TEST_BUG(a_mf_linz(0, 0, +1) >= 1);
54 TEST_BUG(a_mf_s(0, -1, 0) >= 1);
55 TEST_BUG(a_mf_z(0, 0, +1) >= 1);
56 TEST_BUG(a_mf_pi(0, -2, -1, +1, +2) >= 1);
58 return 0;