change gcc to clang in docs.yaml
[liba.git] / test / mf.h
blob3dc6f2f2c1e0b10209cbab86dc2fd6195771f29f
1 #define MAIN_(x) A_CAST_2(x, _mf)
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 main_init(argc, argv, 1);
9 unsigned int e = A_MF_NUL;
10 if (argc > 1)
12 if (strstr(argv[1], "gauss2.")) { e = A_MF_GAUSS2; }
13 else if (strstr(argv[1], "gauss.")) { e = A_MF_GAUSS; }
14 else if (strstr(argv[1], "gbell.")) { e = A_MF_GBELL; }
15 else if (strstr(argv[1], "dsig.")) { e = A_MF_DSIG; }
16 else if (strstr(argv[1], "psig.")) { e = A_MF_PSIG; }
17 else if (strstr(argv[1], "sig.")) { e = A_MF_SIG; }
18 else if (strstr(argv[1], "trap.")) { e = A_MF_TRAP; }
19 else if (strstr(argv[1], "tri.")) { e = A_MF_TRI; }
20 else if (strstr(argv[1], "lins.")) { e = A_MF_LINS; }
21 else if (strstr(argv[1], "linz.")) { e = A_MF_LINZ; }
22 else if (strstr(argv[1], "s.")) { e = A_MF_S; }
23 else if (strstr(argv[1], "z.")) { e = A_MF_Z; }
24 else if (strstr(argv[1], "pi.")) { e = A_MF_PI; }
26 a_float params[6];
27 for (int i = 2; i < argc && i < 8; ++i)
29 params[i - 2] = strtonum(argv[i], A_NULL);
31 if (e != A_MF_NUL)
33 a_float delta = (params[1] - params[0]) / A_FLOAT_C(100.0);
34 for (int i = 0; i < 100; ++i)
36 a_float x = params[0] + delta * a_float_c(i);
37 a_float y = a_mf(e, x, params + 2);
38 debug(A_FLOAT_PRI(, "g,") A_FLOAT_PRI(, "g\n"), x, y);
41 else
43 TEST_BUG(a_mf_gauss(0, 1, 0) >= 1);
44 TEST_BUG(a_mf_gauss2(0, 1, -1, +1, 1) >= 1);
45 TEST_BUG(a_mf_gbell(0, 2, 4, 0) >= 1);
46 TEST_BUG(a_mf_sig(0, 2, 0) >= 0.5);
47 TEST_BUG(a_mf_dsig(0, 5, -2, +5, +2) > 0.99);
48 TEST_BUG(a_mf_psig(0, 5, -2, -5, +2) > 0.99);
49 TEST_BUG(a_mf_trap(0, -2, -1, +1, 2) >= 1);
50 TEST_BUG(a_mf_tri(0, -1, 0, +1) >= 1);
51 TEST_BUG(a_mf_lins(0, -1, 0) >= 1);
52 TEST_BUG(a_mf_linz(0, 0, +1) >= 1);
53 TEST_BUG(a_mf_s(0, -1, 0) >= 1);
54 TEST_BUG(a_mf_z(0, 0, +1) >= 1);
55 TEST_BUG(a_mf_pi(0, -2, -1, +1, +2) >= 1);
57 return 0;