DUNE-FEM (unstable)

Dune::ArithmeticTestSuite Class Reference

Test suite for arithmetic types. More...

#include <dune/common/test/arithmetictestsuite.hh>

Classes

struct  Arithmetic
 tag denoting any arithmetic type More...
 
struct  Boolean
 tag denoting boolean types More...
 
struct  Floating
 tag denoting floating point types More...
 
struct  Integral
 tag denoting integral types More...
 
struct  Signed
 tag denoting signed integral types More...
 
struct  Unsigned
 tag denoting unsigned integral types More...
 

Public Member Functions

template<class T >
void checkDefaultConstruct (Arithmetic arithmetic_tag)
 check the default constructors
 
template<class T >
void checkExplicitIntConvert (Arithmetic arithmetic_tag)
 check explicit conversion from and to int
 
template<class T >
void checkMoveConstruct (Arithmetic arithmetic_tag)
 check the move constructor
 
template<class T >
void checkCopyConstruct (Arithmetic arithmetic_tag)
 check the copy constructor
 
template<class T >
void checkMoveAssign (Arithmetic arithmetic_tag)
 check the move assignment operator
 
template<class T >
void checkCopyAssign (Arithmetic arithmetic_tag)
 check the copy assignment operator
 
template<class T >
void checkEqual (Arithmetic arithmetic_tag)
 check == and != More...
 
template<class T >
void checkPostfixInc (Arithmetic arithmetic_tag)
 check postfix ++ More...
 
template<class T >
void checkPostfixDec (Arithmetic arithmetic_tag)
 check postfix -- More...
 
template<class T >
void checkPrefixPlus (Arithmetic arithmetic_tag)
 check prefix + More...
 
template<class T >
void checkPrefixMinus (Arithmetic arithmetic_tag)
 check prefix - More...
 
template<class T >
void checkPrefixNot (Arithmetic arithmetic_tag)
 check prefix ! More...
 
template<class T >
void checkPrefixBitNot (Boolean arithmetic_tag)
 check prefix ~ More...
 
template<class T >
void checkPrefixInc (Arithmetic arithmetic_tag)
 check postfix ++ More...
 
template<class T >
void checkPrefixDec (Arithmetic arithmetic_tag)
 check postfix -- More...
 
template<class T >
void checkInfixMul (Arithmetic arithmetic_tag)
 check infix * More...
 
template<class T >
void checkInfixDiv (Arithmetic arithmetic_tag)
 check infix / More...
 
template<class T >
void checkInfixRem (Arithmetic arithmetic_tag)
 check infix % More...
 
template<class T >
void checkInfixPlus (Arithmetic arithmetic_tag)
 check infix + More...
 
template<class T >
void checkInfixMinus (Arithmetic arithmetic_tag)
 check infix - More...
 
template<class T >
void checkInfixLShift (Arithmetic arithmetic_tag)
 check infix << More...
 
template<class T >
void checkInfixRShift (Arithmetic arithmetic_tag)
 check infix >> More...
 
template<class T >
void checkInfixLess (Arithmetic arithmetic_tag)
 check infix < More...
 
template<class T >
void checkInfixGreater (Arithmetic arithmetic_tag)
 check infix > More...
 
template<class T >
void checkInfixLessEqual (Arithmetic arithmetic_tag)
 check infix <= More...
 
template<class T >
void checkInfixGreaterEqual (Arithmetic arithmetic_tag)
 check infix >= More...
 
template<class T >
void checkInfixBitAnd (Arithmetic arithmetic_tag)
 check infix & More...
 
template<class T >
void checkInfixBitXor (Arithmetic arithmetic_tag)
 check infix ^ More...
 
template<class T >
void checkInfixBitOr (Arithmetic arithmetic_tag)
 check infix | More...
 
template<class T >
void checkInfixAnd (Arithmetic arithmetic_tag)
 check infix && More...
 
template<class T >
void checkInfixOr (Arithmetic arithmetic_tag)
 check infix || More...
 
 TestSuite (ThrowPolicy policy, std::string name="")
 Create TestSuite. More...
 
 TestSuite (std::string name="", ThrowPolicy policy=ThrowOnRequired)
 Create TestSuite. More...
 
CollectorStream check (bool condition, std::string name="")
 Check condition. More...
 
CollectorStream require (bool condition, std::string name="")
 Check a required condition. More...
 
template<class Exception = AnyException, class Expression >
CollectorStream checkThrow (Expression &&expr, std::string name="")
 Checks that the expression throws. More...
 
template<class Expression >
CollectorStream checkNoThrow (Expression &&expr, std::string name="")
 Checks that the expression doesn't throw. More...
 
template<class Exception = AnyException, class Expression >
CollectorStream requireThrow (Expression &&expr, std::string name="")
 Requires that the expression throws. More...
 
template<class Expression >
CollectorStream requireNoThrow (Expression &&expr, std::string name="")
 Requires that the expression doesn't throw. More...
 
void subTest (const TestSuite &subTest)
 Collect data from a sub-TestSuite. More...
 
 operator bool () const
 Check if this TestSuite failed. More...
 
std::string name () const
 Query name. More...
 
bool report () const
 Print a summary of this TestSuite. More...
 
int exit () const
 Exit the test. More...
 

Static Public Member Functions

template<class T >
static constexpr auto tag (T=T{})
 determine arithmetic tag for the given type More...
 

Detailed Description

Test suite for arithmetic types.

You usually want to call the member function checkArithmetic(). The individual component tests are however available for special needs.

Member Function Documentation

◆ check()

CollectorStream Dune::TestSuite::check ( bool  condition,
std::string  name = "" 
)
inlineinherited

Check condition.

This will throw an exception if the check fails and if the AlwaysThrow policy was used on creation.

Parameters
conditionChecks if this is true and increases the failure counter if not.
nameA name to identify this check. Defaults to ""
Returns
A CollectorStream that can be used to create a diagnostic message to be printed on failure.

References Dune::TestSuite::name().

Referenced by Dune::TestSuite::checkNoThrow(), and Dune::TestSuite::checkThrow().

◆ checkEqual()

template<class T >
void Dune::ArithmeticTestSuite::checkEqual ( Arithmetic  arithmetic_tag)
inline

check == and !=

Note
We do not require the result to be implicitly convertible to bool, but it must be contextually convertible to bool.

◆ checkInfixAnd()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixAnd ( Arithmetic  arithmetic_tag)
inline

check infix &&

Applies to boolean, integral and floating point.

◆ checkInfixBitAnd()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixBitAnd ( Arithmetic  arithmetic_tag)
inline

check infix &

Applies to boolean and integral.

◆ checkInfixBitOr()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixBitOr ( Arithmetic  arithmetic_tag)
inline

check infix |

Applies to boolean and integral.

◆ checkInfixBitXor()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixBitXor ( Arithmetic  arithmetic_tag)
inline

check infix ^

Applies to boolean and integral.

◆ checkInfixDiv()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixDiv ( Arithmetic  arithmetic_tag)
inline

check infix /

Applies to boolean, integral, and floating point.

◆ checkInfixGreater()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixGreater ( Arithmetic  arithmetic_tag)
inline

check infix >

Applies to boolean, integral, and floating point.

◆ checkInfixGreaterEqual()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixGreaterEqual ( Arithmetic  arithmetic_tag)
inline

check infix >=

Applies to boolean, integral, and floating point.

◆ checkInfixLess()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixLess ( Arithmetic  arithmetic_tag)
inline

check infix <

Applies to boolean, integral, and floating point.

◆ checkInfixLessEqual()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixLessEqual ( Arithmetic  arithmetic_tag)
inline

check infix <=

Applies to boolean, integral, and floating point.

◆ checkInfixLShift()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixLShift ( Arithmetic  arithmetic_tag)
inline

check infix <<

Applies to boolean and integral.

◆ checkInfixMinus()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixMinus ( Arithmetic  arithmetic_tag)
inline

check infix -

Applies to boolean, integral, and floating point.

◆ checkInfixMul()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixMul ( Arithmetic  arithmetic_tag)
inline

check infix *

Applies to boolean, integral, and floating point.

◆ checkInfixOr()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixOr ( Arithmetic  arithmetic_tag)
inline

check infix ||

Applies to boolean, integral and floating point.

◆ checkInfixPlus()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixPlus ( Arithmetic  arithmetic_tag)
inline

check infix +

Applies to boolean, integral, and floating point.

◆ checkInfixRem()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixRem ( Arithmetic  arithmetic_tag)
inline

check infix %

Applies to boolean and integral.

◆ checkInfixRShift()

template<class T >
void Dune::ArithmeticTestSuite::checkInfixRShift ( Arithmetic  arithmetic_tag)
inline

check infix >>

Applies to boolean and integral.

◆ checkNoThrow()

template<class Expression >
CollectorStream Dune::TestSuite::checkNoThrow ( Expression &&  expr,
std::string  name = "" 
)
inlineinherited

Checks that the expression doesn't throw.

This will throw an exception if the check fails and if the AlwaysThrow policy was used on creation.

Parameters
exprA nullary functor that is expected not to throw an exception on evaluation
nameA name to identify this check. Defaults to ""
Returns
A CollectorStream that can be used to create a diagnostic message to be printed on failure.
Example:
checkNoThrow([]{ throw std::runtime_Error("error"); }, "Expected not to thrown"); //fails
CollectorStream checkNoThrow(Expression &&expr, std::string name="")
Checks that the expression doesn't throw.
Definition: testsuite.hh:163

References Dune::TestSuite::check(), and Dune::TestSuite::name().

◆ checkPostfixDec()

template<class T >
void Dune::ArithmeticTestSuite::checkPostfixDec ( Arithmetic  arithmetic_tag)
inline

check postfix --

Applies to integral (no boolean), and floating point.

◆ checkPostfixInc()

template<class T >
void Dune::ArithmeticTestSuite::checkPostfixInc ( Arithmetic  arithmetic_tag)
inline

check postfix ++

Applies to boolean (deprecated), integral, and floating point.

◆ checkPrefixBitNot()

template<class T >
void Dune::ArithmeticTestSuite::checkPrefixBitNot ( Boolean  arithmetic_tag)
inline

check prefix ~

Applies to boolean and integral.

◆ checkPrefixDec()

template<class T >
void Dune::ArithmeticTestSuite::checkPrefixDec ( Arithmetic  arithmetic_tag)
inline

check postfix --

Applies to integral (no boolean), and floating point.

◆ checkPrefixInc()

template<class T >
void Dune::ArithmeticTestSuite::checkPrefixInc ( Arithmetic  arithmetic_tag)
inline

check postfix ++

Applies to boolean (deprecated), integral, and floating point.

◆ checkPrefixMinus()

template<class T >
void Dune::ArithmeticTestSuite::checkPrefixMinus ( Arithmetic  arithmetic_tag)
inline

check prefix -

Applies to boolean, integral, and floating point.

◆ checkPrefixNot()

template<class T >
void Dune::ArithmeticTestSuite::checkPrefixNot ( Arithmetic  arithmetic_tag)
inline

check prefix !

Applies to boolean, integral, and floating point.

◆ checkPrefixPlus()

template<class T >
void Dune::ArithmeticTestSuite::checkPrefixPlus ( Arithmetic  arithmetic_tag)
inline

check prefix +

Applies to boolean, integral, and floating point.

◆ checkThrow()

template<class Exception = AnyException, class Expression >
CollectorStream Dune::TestSuite::checkThrow ( Expression &&  expr,
std::string  name = "" 
)
inlineinherited

Checks that the expression throws.

This will throw an exception if the check fails and if the AlwaysThrow policy was used on creation.

Parameters
exprA nullary functor that is expected to throw an exception on evaluation that is of type Exception or any exception if the template parameter is omitted.
nameA name to identify this check. Defaults to ""
Returns
A CollectorStream that can be used to create a diagnostic message to be printed on failure.
Example:
checkThrow<Exception>([]{ throw Exception; }, "Expected an 'Exception' to be thrown");
checkThrow([]{ throw std::runtime_Error("error"); }, "Expected any exception to be thrown");
Base class for Dune-Exceptions.
Definition: exceptions.hh:96
CollectorStream checkThrow(Expression &&expr, std::string name="")
Checks that the expression throws.
Definition: testsuite.hh:144

References Dune::TestSuite::check(), and Dune::TestSuite::name().

◆ exit()

int Dune::TestSuite::exit ( ) const
inlineinherited

Exit the test.

This will print a summary of the test and return an integer to be used on program exit.

Returns
1 if any of the executed tests failed, otherwise 0.

References Dune::TestSuite::report().

◆ name()

◆ operator bool()

Dune::TestSuite::operator bool ( ) const
inlineexplicitinherited

Check if this TestSuite failed.

Returns
False if any of the executed tests failed, otherwise true.

◆ report()

bool Dune::TestSuite::report ( ) const
inlineinherited

Print a summary of this TestSuite.

Returns
False if any of the executed tests failed, otherwise true.

References Dune::TestSuite::name().

Referenced by Dune::TestSuite::exit().

◆ require()

CollectorStream Dune::TestSuite::require ( bool  condition,
std::string  name = "" 
)
inlineinherited

Check a required condition.

This will always throw an exception if the check fails.

Parameters
conditionChecks if this is true and increases the failure counter if not.
nameA name to identify this check. Defaults to ""
Returns
A CollectorStream that can be used to create a diagnostic message to be printed on failure.

References Dune::TestSuite::name().

Referenced by Dune::TestSuite::requireNoThrow(), and Dune::TestSuite::requireThrow().

◆ requireNoThrow()

template<class Expression >
CollectorStream Dune::TestSuite::requireNoThrow ( Expression &&  expr,
std::string  name = "" 
)
inlineinherited

Requires that the expression doesn't throw.

This will throw an exception if the check fails.

Parameters
exprA nullary functor that is expected not to throw an exception on evaluation
nameA name to identify this check. Defaults to ""
Returns
A CollectorStream that can be used to create a diagnostic message to be printed on failure.
Example:
requireNoThrow([]{ throw std::runtime_Error("error"); }, "Expected not to thrown"); //fails
CollectorStream requireNoThrow(Expression &&expr, std::string name="")
Requires that the expression doesn't throw.
Definition: testsuite.hh:202

References Dune::TestSuite::name(), and Dune::TestSuite::require().

◆ requireThrow()

template<class Exception = AnyException, class Expression >
CollectorStream Dune::TestSuite::requireThrow ( Expression &&  expr,
std::string  name = "" 
)
inlineinherited

Requires that the expression throws.

This will throw an exception if the check fails.

Parameters
exprA nullary functor that is expected to throw an exception on evaluation that is of type Exception or any exception if the template parameter is omitted.
nameA name to identify this check. Defaults to ""
Returns
A CollectorStream that can be used to create a diagnostic message to be printed on failure.
Example:
requireThrow<Exception>([]{ throw Exception; }, "Expected an 'Exception' to be thrown");
requireThrow([]{ throw std::runtime_Error("error"); }, "Expected any exception to be thrown");
CollectorStream requireThrow(Expression &&expr, std::string name="")
Requires that the expression throws.
Definition: testsuite.hh:183

References Dune::TestSuite::name(), and Dune::TestSuite::require().

◆ subTest()

void Dune::TestSuite::subTest ( const TestSuite subTest)
inlineinherited

Collect data from a sub-TestSuite.

This will incorporate the accumulated results of the sub-TestSuite into this one. If the sub-TestSuite failed, i.e., contained failed checks, a summary will be printed.

References Dune::TestSuite::subTest().

Referenced by Dune::TestSuite::subTest().

◆ tag()

template<class T >
static constexpr auto Dune::ArithmeticTestSuite::tag ( = T{})
inlinestaticconstexpr

determine arithmetic tag for the given type

T can be either one of the fundamental arithmetic types, in which case a default-constructed tag object for that type is returned. Or it can be a class derived from Arithmetic, in which case a default-constructed object of that class is is returned.

◆ TestSuite() [1/2]

Dune::TestSuite::TestSuite ( std::string  name = "",
ThrowPolicy  policy = ThrowOnRequired 
)
inline

Create TestSuite.

Parameters
nameA name to identify this TestSuite. Defaults to "".
policyIf AlwaysThrow any failing check will throw, otherwise only required checks will do. Defaults to ThrowOnRequired

◆ TestSuite() [2/2]

Dune::TestSuite::TestSuite ( ThrowPolicy  policy,
std::string  name = "" 
)
inline

Create TestSuite.

Parameters
nameA name to identify this TestSuite. Defaults to "".
policyIf AlwaysThrow any failing check will throw, otherwise only required checks will do.

The documentation for this class was generated from the following file:
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 20, 23:30, 2024)