Testing facilities

constexpr const int MultiPatchTests::random_seed = 100

Seed value of the random number generation engines.

constexpr const CCTK_REAL MultiPatchTests::fd_delta = 1.0e-3

The “grid spacing” used in finite difference operators

constexpr const CCTK_REAL MultiPatchTests::fd_comp_tol = 1.0e-7

The floating point comparison tolerance when testing the equality of exact and FD computed derivatives

template<typename fp_type>
inline bool MultiPatchTests::isapprox(fp_type x, fp_type y, fp_type atol = 0.0)

Test two floating point values for approximate equality.

This function is based on the Julia langage implementation

Inputs:

  1. fp_type: A floating point type.

  2. fp_type x: The first number to compare.

  3. fp_type y: The second number to compare.

  4. fp_type atol: The absolute tolerance for the comparison.

  5. fp_type rtol: The relative tolerance of the comparison.

Returns:

True if x ~ y, false otherwise.

template<typename T>
inline bool MultiPatchTests::within(T variable, T boundary)

Test if -boundary < variable < boundary. Fails if variable ~= (+/- boundary).

Inputs:

  1. T: A floating point type.

  2. T variable: The variable to test.

  3. T boundary: The absolute value of the region boundary

Returns:

True if the variable is within the region, false otherwise.

template<typename T>
inline bool MultiPatchTests::at_boundary(T variable, T boundary)

Test if -boundary ~= variable or variable ~= boundary.

Inputs

  1. T: A floating point type.

  2. T variable: The variable to test.

  3. T boundary: The absolute value of the region boundary

Returns:

True if variable ~= boundary, false otherwise.

enum class MultiPatchTests::string_color

Tag representing possible colors to apply to diagnostic strings.

Values:

enumerator green
enumerator red
template<string_color color>
std::string MultiPatchTests::colored(const std::string &str)

Formats a string to be colored in ANSI compatible terminals.

Inputs:

  1. string_color color: The color to use.

  2. std::string &str: The string to color.

Returns:

The colored string.

const auto MultiPatchTests::PASSED = colored<string_color::green>("PASSED")

Test passed banner.

const auto MultiPatchTests::FAILED = colored<string_color::red>("FAILED")

Test failed banner.

enum class MultiPatchTests::fd_direction

Tags for the direction that a finite difference derivative will be performed

Values:

enumerator x
enumerator y
enumerator z
template<fd_direction dir, typename vector_t, typename function_t>
inline vector_t MultiPatchTests::fd_4(const function_t &function, const vector_t &point)

Computes the fourth order accurate finite difference approximation to the first derivative of a function that takes a vector as input and produces another vector as output in a specified direction.

Inputs:

  1. fd_direction dir: The direction of the derivative

  2. vector_t: A vector/array type.

  3. function_t: The type signature of the function being derived.

  4. function_t &function: The function to be derived.

  5. const vector_t &point: The point where the derivative is to be computed.

Returns:

The first derivative of function in the specified direction and point.

template<fd_direction dir_inner, fd_direction dir_outer, typename vector_t, typename function_t>
inline vector_t MultiPatchTests::fd2_4(const function_t &function, const vector_t &point)

Computes the fourth order accurate finite difference approximation to the second derivative of a function that takes a vector as input and produces another vector as output in a specified direction.

Inputs:

  1. fd_direction dir_inner: The direction of the first derivative

  2. fd_direction dir_inner: The direction of the second derivative

  3. vector_t: A vector/array type.

  4. function_t: The type signature of the function being derived.

  5. function_t &function: The function to be derived.

  6. const vector_t &point: The point where the derivative is to be computed.

Returns:

The second derivative of function in the specified direction and point.