15 #include "Framework/CheckWithRandomValues.hpp"
16 #include "Framework/SetupLocalPythonEnvironment.hpp"
24 #include "Utilities/Overloader.hpp"
26 namespace TestHelpers {
29 template <
size_t VolumeDim,
typename Fr,
class... MemberArgs,
class T>
32 const std::string& python_function_prefix,
const T& used_for_size,
34 const MemberArgs&... member_args) noexcept {
36 using CallOperatorFunction =
37 Scalar<T> (MathFunc::*)(
const tnsr::I<T, VolumeDim, Fr>&)
const noexcept;
38 using FirstDerivFunction =
39 tnsr::i<T, VolumeDim, Fr> (MathFunc::*)(
const tnsr::I<T, VolumeDim, Fr>&)
41 using SecondDerivFunction =
42 tnsr::ii<T, VolumeDim, Fr> (MathFunc::*)(
const tnsr::I<T, VolumeDim, Fr>&)
44 using ThirdDerivFunction = tnsr::iii<T, VolumeDim, Fr> (MathFunc::*)(
45 const tnsr::I<T, VolumeDim, Fr>&)
const noexcept;
47 const auto member_args_tuple = std::make_tuple(member_args...);
51 CallOperatorFunction func{&MathFunc::operator()};
53 INFO(
"Testing call operator...")
54 pypp::check_with_random_values<1>(
55 func, *math_function, "TestFunctions",
56 python_function_prefix + "_call_operator", random_value_bounds,
57 member_args_tuple, used_for_size);
58 INFO("Done testing
call operator...")
60 FirstDerivFunction d_func{&MathFunc::first_deriv};
61 INFO(
"Testing first derivative...")
62 pypp::check_with_random_values<1>(
63 d_func, *math_function, "TestFunctions",
64 python_function_prefix + "_first_deriv", random_value_bounds,
65 member_args_tuple, used_for_size);
66 INFO("Done testing first derivative...")
68 SecondDerivFunction d2_func{&MathFunc::second_deriv};
69 INFO(
"Testing second derivative...")
70 pypp::check_with_random_values<1>(
71 d2_func, *math_function, "TestFunctions",
72 python_function_prefix + "_second_deriv", random_value_bounds,
73 member_args_tuple, used_for_size);
74 INFO("Done testing second derivative...")
76 ThirdDerivFunction d3_func{&MathFunc::third_deriv};
77 INFO(
"Testing third derivative...")
78 pypp::check_with_random_values<1>(
79 d3_func, *math_function, "TestFunctions",
80 python_function_prefix + "_third_deriv", random_value_bounds,
81 member_args_tuple, used_for_size);
82 INFO("Done testing third derivative...")
86 helper(in_math_function);
89 if constexpr (VolumeDim == 1) {
98 auto coords_tensor = make_with_random_values<tnsr::I<T, VolumeDim, Fr>>(
99 nn_generator, nn_distribution, used_for_size);
100 T coords_T = get<0>(coords_tensor);
103 (*in_math_function)(coords_T));
105 const T deriv_from_tensor =
106 std::move(get<0>(in_math_function->first_deriv(coords_tensor)));
108 in_math_function->first_deriv(coords_T));
110 const T second_deriv_from_tensor =
111 std::move(get<0, 0>(in_math_function->second_deriv(coords_tensor)));
113 in_math_function->second_deriv(coords_T));
115 const T third_deriv_from_tensor =
116 std::move(get<0, 0, 0>(in_math_function->third_deriv(coords_tensor)));
118 in_math_function->third_deriv(coords_T));
138 template <
class MathFunctionType,
class T,
class... MemberArgs>
140 const std::string& python_function_prefix,
const T& used_for_size,
142 const MemberArgs&... member_args) noexcept {
145 typename MathFunctionType::frame>>(
146 std::move(in_math_function)),
147 python_function_prefix, used_for_size, random_value_bounds,
151 template <
class MathFunctionType,
class T,
class... MemberArgs>
152 void check(MathFunctionType in_math_function,
153 const std::string& python_function_prefix,
const T& used_for_size,
155 const MemberArgs&... member_args) noexcept {
158 typename MathFunctionType::frame>>(
159 std::make_unique<MathFunctionType>(std::move(in_math_function))),
160 python_function_prefix, used_for_size, random_value_bounds,