Classes | Macros | Functions
TestHelpers.hpp File Reference

Commonly used routines, functions and definitions shared amongst unit tests. More...

#include "tests/Unit/TestingFramework.hpp"
#include <algorithm>
#include <array>
#include <boost/algorithm/string/predicate.hpp>
#include <cstddef>
#include <iterator>
#include <memory>
#include <ostream>
#include <random>
#include <string>
#include <tuple>
#include "DataStructures/Variables.hpp"
#include "ErrorHandling/Assert.hpp"
#include "ErrorHandling/Error.hpp"
#include "Parallel/RegisterDerivedClassesWithCharm.hpp"
#include "Parallel/Serialize.hpp"
#include "Utilities/ContainerHelpers.hpp"
#include "Utilities/DereferenceWrapper.hpp"
#include "Utilities/Gsl.hpp"
#include "Utilities/MakeArray.hpp"
#include "Utilities/Requires.hpp"
#include "Utilities/StdArrayHelpers.hpp"
#include "Utilities/TMPL.hpp"
#include "Utilities/Tuple.hpp"
#include "Utilities/TypeTraits.hpp"

Go to the source code of this file.

Classes

struct  NonCopyable
 
class  DoesNotThrow
 
class  DoesThrow
 
struct  check_variables_approx< T >
 
struct  check_variables_approx< Variables< TagList > >
 

Macros

#define CHECK_OP(a, op, b, c)
 Check a op b == c and also the op= version. More...
 
#define MAKE_GENERATOR(...)
 MAKE_GENERATOR(NAME [, SEED]) declares a variable of name NAME containing a generator of type std::mt19937. More...
 
#define CHECK_VARIABLES_APPROX(a, b)
 A wrapper around Catch's CHECK macro that checks approximate equality of each entry in each tag within a variables. More...
 
#define CHECK_VARIABLES_CUSTOM_APPROX(a, b, appx)
 Same as CHECK_VARIABLES_APPROX, but with a user-defined Approx. The third argument should be of type Approx. More...
 
#define CHECK_ELEMENT_WISE_FUNCTION_APPROX(function, arguments)
 A test utility for verifying that an element-wise function, function acts identically to the same operation applied to each element of a container separately. This macro invokes test_element_wise_function() (which gives a more complete documentation of the element-wise checking operations and arguments). More...
 
#define CHECK_CUSTOM_ELEMENT_WISE_FUNCTION_APPROX( function, arguments, at_operator, size_of_operator)
 Same as CHECK_ELEMENT_WISE_FUNCTION_APPROX, but with a user-defined function at_operator and size_of_operator, each of which correspond to arguments of test_element_wise_function() (which gives a more complete documentation of the element-wise checking operations and arguments). More...
 

Functions

template<typename T >
serialize_and_deserialize (const T &t)
 Serializes and deserializes an object t of type T
 
template<typename T >
void test_serialization (const T &t)
 Tests the serialization of comparable types. More...
 
template<typename B , typename D , typename... Args>
void test_serialization_via_base (Args &&... args)
 Test the serialization of a derived class via a base class pointer. More...
 
template<typename T , Requires< tt::has_equivalence< T >::value > = nullptr>
void test_copy_semantics (const T &a)
 Test for copy semantics assuming operator== is implement correctly.
 
template<typename T , Requires< tt::has_equivalence< T >::value > = nullptr, typename... Args>
void test_move_semantics (T &&a, const T &comparison, Args &&... args)
 Test for move semantics assuming operator== is implemented correctly. More...
 
template<typename Container >
void test_iterators (Container &c)
 
template<typename Container >
void test_reverse_iterators (Container &c)
 
template<typename T , typename U >
void check_cmp (const T &less, const U &greater)
 Function to test comparison operators. Pass values with less < greater.
 
template<typename Invocable , size_t VolumeDim>
std::array< double, VolumeDim > numerical_derivative (const Invocable &map, const std::array< double, VolumeDim > &x, const size_t direction, const double delta)
 Calculates the derivative of an Invocable at a point x - represented by an array of doubles - in the domain of map with a sixth-order finite difference method. More...
 
bool operator== (const NonCopyable &, const NonCopyable &) noexcept
 
bool operator!= (const NonCopyable &a, const NonCopyable &b) noexcept
 
std::ostreamoperator<< (std::ostream &os, const NonCopyable &) noexcept
 
template<typename Exception , typename ThrowingFunctor >
void test_throw_exception (const ThrowingFunctor &func, const Exception &expected)
 Execute func and check that it throws an exception expected. More...
 
template<typename ElementWiseFunction , typename AtFunction = GetContainerElement, typename SizeFunction = GetContainerSize, typename... Arguments>
void test_element_wise_function (ElementWiseFunction element_wise_function, const gsl::not_null< std::tuple< Arguments... > *> arguments, AtFunction at=GetContainerElement{}, SizeFunction size=GetContainerSize{}, Approx custom_approx=approx) noexcept
 Utility function for verifying the action of an element-wise function on containers, or on some combination of containers and compatible non-containers (e.g. DataVectors with doubles). More...
 

Detailed Description

Commonly used routines, functions and definitions shared amongst unit tests.

Function Documentation

◆ test_move_semantics()

template<typename T , Requires< tt::has_equivalence< T >::value > = nullptr, typename... Args>
void test_move_semantics ( T &&  a,
const T &  comparison,
Args &&...  args 
)

Test for move semantics assuming operator== is implemented correctly.

Requires: std::is_rvalue_reference<decltype(a)>::value is true. If T is not default constructible, you pass additional arguments that are used to construct a T.