Go to the documentation of this file.
15 #define REL_PERTURBATION 1e-6
18 #define DERIV_TEST_CUSTOM_PERTURBATION(f, a, b, tol, rel_pert) \
20 const Real da = rel_pert * a; \
21 const Real db = rel_pert * b; \
22 const Real df_da_fd = (f(a + da, b) - f(a - da, b)) / (2 * da); \
23 const Real df_db_fd = (f(a, b + db) - f(a, b - db)) / (2 * db); \
24 Real f_value, df_da, df_db; \
25 f(a, b, f_value, df_da, df_db); \
26 REL_TEST(f(a, b), f_value, REL_TOL_CONSISTENCY); \
27 REL_TEST(df_da, df_da_fd, tol); \
28 REL_TEST(df_db, df_db_fd, tol); \
32 #define DERIV_TEST(f, a, b, tol) \
34 DERIV_TEST_CUSTOM_PERTURBATION(f, a, b, tol, REL_PERTURBATION); \
38 #define DERIV_TEST_1D(f, dfda, a, tol) \
40 const Real da = REL_PERTURBATION * a; \
41 const Real df_da_fd = (f(a + da) - f(a - da)) / (2 * da); \
42 Real df_da = dfda(a); \
43 REL_TEST(df_da, df_da_fd, tol); \
47 #define NOT_IMPLEMENTED_TEST_VALUE(f) \
53 catch (const std::exception & x) \
55 std::string msg(x.what()); \
56 EXPECT_TRUE(msg.find("not implemented") != std::string::npos); \
61 #define NOT_IMPLEMENTED_TEST_DERIV(f) \
65 Real f_val, df_da, df_db; \
66 f(0, 0, f_val, df_da, df_db); \
68 catch (const std::exception & x) \
70 std::string msg(x.what()); \
71 EXPECT_TRUE(msg.find("not implemented") != std::string::npos); \