FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
test_system.hpp File Reference
#include <kernel/base_header.hpp>
#include <kernel/backend.hpp>
#include <kernel/util/type_traits.hpp>
#include <kernel/util/exception.hpp>
#include <kernel/util/math.hpp>
#include <string>
#include <exception>
#include <list>
#include <typeinfo>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>

Go to the source code of this file.

Classes

class  FEAT::TestSystem::TestFailedException
 exception thrown by the check method in UnitTest More...
 
class  FEAT::TestSystem::TestList
 list of all instantiated tests More...
 
class  FEAT::TestSystem::TestList::DeleteOnDestruction
 
class  FEAT::TestSystem::UnitTest
 base class for all Tests More...
 

Namespaces

namespace  FEAT
 FEAT namespace.
 
namespace  FEAT::TestSystem
 TestSystem namespace.
 

Macros

#define CHECK_INTERNAL(was_ok, message)
 
#define SPAWN_UNIT_TEST_0T(c, ...)   static c FEAT_CONCAT(unit_test_, __COUNTER__)
 spawns a unit test of class c with 0 template parameters and no constructor arguments More...
 
#define SPAWN_UNIT_TEST_0T_P(c, ...)   static c FEAT_CONCAT(unit_test_, __COUNTER__)(__VA_ARGS__)
 spawns a unit test of class c with 0 template parameters and a variadic number of constructor arguments More...
 
#define SPAWN_UNIT_TEST_1T(c, t1)   static c<t1> FEAT_CONCAT(unit_test_, __COUNTER__)
 spawns a unit test of class c with 1 template parameters and no constructor arguments More...
 
#define SPAWN_UNIT_TEST_1T_P(c, t1, ...)   static c<t1> FEAT_CONCAT(unit_test_, __COUNTER__)(__VA_ARGS__)
 spawns a unit test of class c with 1 template parameter and a variadic number of constructor arguments More...
 
#define SPAWN_UNIT_TEST_2T(c, t1, t2)   static c<t1,t2> FEAT_CONCAT(unit_test_, __COUNTER__)
 spawns a unit test of class c with 2 template parameters and no constructor arguments More...
 
#define SPAWN_UNIT_TEST_2T_P(c, t1, t2, ...)   static c<t1,t2> FEAT_CONCAT(unit_test_, __COUNTER__)(__VA_ARGS__)
 spawns a unit test of class c with 2 template parameters and a variadic number of constructor arguments More...
 
#define SPAWN_UNIT_TEST_3T(c, t1, t2, t3)   static c<t1,t2,t3> FEAT_CONCAT(unit_test_, __COUNTER__)
 spawns a unit test of class c with 3 template parameters and no constructor arguments More...
 
#define SPAWN_UNIT_TEST_3T_P(c, t1, t2, t3, ...)   static c<t1,t2,t3> FEAT_CONCAT(unit_test_, __COUNTER__)(__VA_ARGS__)
 spawns a unit test of class c with 3 template parameters and a variadic number of constructor arguments More...
 
#define SPAWN_UNIT_TEST_4T(c, t1, t2, t3, t4)   static c<t1,t2,t3,t4> FEAT_CONCAT(unit_test_, __COUNTER__)
 spawns a unit test of class c with 4 template parameters and no constructor arguments More...
 
#define SPAWN_UNIT_TEST_4T_P(c, t1, t2, t3, t4, ...)   static c<t1,t2,t3,t4> FEAT_CONCAT(unit_test_, __COUNTER__)(__VA_ARGS__)
 spawns a unit test of class c with 4 template parameters and a variadic number of constructor arguments More...
 
#define SPAWN_UNIT_TEST_5T(c, t1, t2, t3, t4, t5)   static c<t1,t2,t3,t4,t5> FEAT_CONCAT(unit_test_, __COUNTER__)
 spawns a unit test of class c with 5 template parameters and no constructor arguments More...
 
#define SPAWN_UNIT_TEST_5T_P(c, t1, t2, t3, t4, t5, ...)   static c<t1,t2,t3,t4,t5> FEAT_CONCAT(unit_test_, __COUNTER__)(__VA_ARGS__)
 spawns a unit test of class c with 5 template parameters and a variadic number of constructor arguments More...
 
#define TEST(pre, test, post)
 runs the given test with pre- and postprocessing More...
 
#define TEST_CHECK(a)
 checks if a is true More...
 
#define TEST_CHECK_EQUAL(a, b)
 checks if a == b More...
 
#define TEST_CHECK_EQUAL_WITHIN_EPS(a, b, eps)
 checks if |a - b| <= epsilon More...
 
#define TEST_CHECK_IN_RANGE(x, a, b)
 checks if a <= x <= b More...
 
#define TEST_CHECK_LESS_THAN(a, b)
 checks if a < b More...
 
#define TEST_CHECK_MSG(a, msg)
 checks if a is true; prints msg if a is false More...
 
#define TEST_CHECK_NOT_EQUAL(a, b)
 checks if a != b More...
 
#define TEST_CHECK_RELATIVE(a, b, eps)
 checks if |a - b| <= epsilon*|b| More...
 
#define TEST_CHECK_STRINGIFY_EQUAL(a, b)
 checks if stringify(a) == stringify(b) More...
 
#define TEST_CHECK_THROWS(a, b)
 checks if a throws an exception of type b More...
 

Functions

template<typename DT_ >
DT_ FEAT::TestSystem::relaxed_tol ()
 
template<>
double FEAT::TestSystem::relaxed_tol< double > ()
 
template<>
float FEAT::TestSystem::relaxed_tol< float > ()
 
template<typename DT_ >
DT_ FEAT::TestSystem::tol ()
 
template<>
double FEAT::TestSystem::tol< double > ()
 
template<>
float FEAT::TestSystem::tol< float > ()
 

Detailed Description

Implementation of Test and related classes.

Definition in file test_system.hpp.

Macro Definition Documentation

◆ CHECK_INTERNAL

#define CHECK_INTERNAL (   was_ok,
  message 
)
Value:
if(! (was_ok))\
throw FEAT::TestSystem::TestFailedException(__func__, __FILE__, __LINE__, message);
exception thrown by the check method in UnitTest
Definition: test_system.hpp:45

Definition at line 24 of file test_system.hpp.

◆ SPAWN_UNIT_TEST_0T

#define SPAWN_UNIT_TEST_0T (   c,
  ... 
)    static c FEAT_CONCAT(unit_test_, __COUNTER__)

spawns a unit test of class c with 0 template parameters and no constructor arguments

Definition at line 475 of file test_system.hpp.

◆ SPAWN_UNIT_TEST_0T_P

#define SPAWN_UNIT_TEST_0T_P (   c,
  ... 
)    static c FEAT_CONCAT(unit_test_, __COUNTER__)(__VA_ARGS__)

spawns a unit test of class c with 0 template parameters and a variadic number of constructor arguments

Definition at line 493 of file test_system.hpp.

◆ SPAWN_UNIT_TEST_1T

#define SPAWN_UNIT_TEST_1T (   c,
  t1 
)    static c<t1> FEAT_CONCAT(unit_test_, __COUNTER__)

spawns a unit test of class c with 1 template parameters and no constructor arguments

Definition at line 478 of file test_system.hpp.

◆ SPAWN_UNIT_TEST_1T_P

#define SPAWN_UNIT_TEST_1T_P (   c,
  t1,
  ... 
)    static c<t1> FEAT_CONCAT(unit_test_, __COUNTER__)(__VA_ARGS__)

spawns a unit test of class c with 1 template parameter and a variadic number of constructor arguments

Definition at line 496 of file test_system.hpp.

◆ SPAWN_UNIT_TEST_2T

#define SPAWN_UNIT_TEST_2T (   c,
  t1,
  t2 
)    static c<t1,t2> FEAT_CONCAT(unit_test_, __COUNTER__)

spawns a unit test of class c with 2 template parameters and no constructor arguments

Definition at line 481 of file test_system.hpp.

◆ SPAWN_UNIT_TEST_2T_P

#define SPAWN_UNIT_TEST_2T_P (   c,
  t1,
  t2,
  ... 
)    static c<t1,t2> FEAT_CONCAT(unit_test_, __COUNTER__)(__VA_ARGS__)

spawns a unit test of class c with 2 template parameters and a variadic number of constructor arguments

Definition at line 499 of file test_system.hpp.

◆ SPAWN_UNIT_TEST_3T

#define SPAWN_UNIT_TEST_3T (   c,
  t1,
  t2,
  t3 
)    static c<t1,t2,t3> FEAT_CONCAT(unit_test_, __COUNTER__)

spawns a unit test of class c with 3 template parameters and no constructor arguments

Definition at line 484 of file test_system.hpp.

◆ SPAWN_UNIT_TEST_3T_P

#define SPAWN_UNIT_TEST_3T_P (   c,
  t1,
  t2,
  t3,
  ... 
)    static c<t1,t2,t3> FEAT_CONCAT(unit_test_, __COUNTER__)(__VA_ARGS__)

spawns a unit test of class c with 3 template parameters and a variadic number of constructor arguments

Definition at line 502 of file test_system.hpp.

◆ SPAWN_UNIT_TEST_4T

#define SPAWN_UNIT_TEST_4T (   c,
  t1,
  t2,
  t3,
  t4 
)    static c<t1,t2,t3,t4> FEAT_CONCAT(unit_test_, __COUNTER__)

spawns a unit test of class c with 4 template parameters and no constructor arguments

Definition at line 487 of file test_system.hpp.

◆ SPAWN_UNIT_TEST_4T_P

#define SPAWN_UNIT_TEST_4T_P (   c,
  t1,
  t2,
  t3,
  t4,
  ... 
)    static c<t1,t2,t3,t4> FEAT_CONCAT(unit_test_, __COUNTER__)(__VA_ARGS__)

spawns a unit test of class c with 4 template parameters and a variadic number of constructor arguments

Definition at line 505 of file test_system.hpp.

◆ SPAWN_UNIT_TEST_5T

#define SPAWN_UNIT_TEST_5T (   c,
  t1,
  t2,
  t3,
  t4,
  t5 
)    static c<t1,t2,t3,t4,t5> FEAT_CONCAT(unit_test_, __COUNTER__)

spawns a unit test of class c with 5 template parameters and no constructor arguments

Definition at line 490 of file test_system.hpp.

◆ SPAWN_UNIT_TEST_5T_P

#define SPAWN_UNIT_TEST_5T_P (   c,
  t1,
  t2,
  t3,
  t4,
  t5,
  ... 
)    static c<t1,t2,t3,t4,t5> FEAT_CONCAT(unit_test_, __COUNTER__)(__VA_ARGS__)

spawns a unit test of class c with 5 template parameters and a variadic number of constructor arguments

Definition at line 508 of file test_system.hpp.

◆ TEST

#define TEST (   pre,
  test,
  post 
)
Value:
do { \
pre; \
try { \
test; \
} catch (const FEAT::TestSystem::TestFailedException & test_e) { \
post; \
throw; } \
post; \
} while (false)

runs the given test with pre- and postprocessing

Definition at line 462 of file test_system.hpp.

◆ TEST_CHECK

#define TEST_CHECK (   a)
Value:
do { \
CHECK_INTERNAL(a, this->_id + "\n" + "Check '" #a "' failed") \
} while (false)

checks if a is true

Definition at line 400 of file test_system.hpp.

◆ TEST_CHECK_EQUAL

#define TEST_CHECK_EQUAL (   a,
  b 
)
Value:
do { \
CHECK_INTERNAL((a)==(b), this->_id + "\n" + "Expected '" #a "' to equal \n'" + FEAT::stringify(b) + "'\nbut got\n'" + FEAT::stringify(a) + "'")\
} while (false)
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:993

checks if a == b

Definition at line 374 of file test_system.hpp.

◆ TEST_CHECK_EQUAL_WITHIN_EPS

#define TEST_CHECK_EQUAL_WITHIN_EPS (   a,
  b,
  eps 
)
Value:
do { \
CHECK_INTERNAL(((a) <= ((b) + (eps))) && ((b) <= ((a) + (eps))), \
this->_id + "\n" + "Expected '|" #a " - " #b \
"|' <= '" + FEAT::stringify(eps) + "' but was '" + \
FEAT::stringify((a) < (b) ? (b) - (a) : (a) - (b)) + "'" \
+ ", with " #a "=" + FEAT::stringify(a) + " and " #b "=" + FEAT::stringify(b))\
} while (false)

checks if |a - b| <= epsilon

Definition at line 435 of file test_system.hpp.

◆ TEST_CHECK_IN_RANGE

#define TEST_CHECK_IN_RANGE (   x,
  a,
  b 
)
Value:
do { \
CHECK_INTERNAL(((a) <= (x)) && ((x) <= (b)), this->_id + "\n" + "Expected '" #x "' that is'" + FEAT::stringify(x) + "' to be in range [" + FEAT::stringify(a) + "," + FEAT::stringify(b) + "]")\
} while (false)

checks if a <= x <= b

Definition at line 386 of file test_system.hpp.

◆ TEST_CHECK_LESS_THAN

#define TEST_CHECK_LESS_THAN (   a,
  b 
)
Value:
do { \
CHECK_INTERNAL((a) < (b), this->_id + "\n" + "Expected '" #a "' to be less than '" + FEAT::stringify(b) + "' but got '" + FEAT::stringify(a) + "'")\
} while (false)

checks if a < b

Definition at line 456 of file test_system.hpp.

◆ TEST_CHECK_MSG

#define TEST_CHECK_MSG (   a,
  msg 
)
Value:
do { \
CHECK_INTERNAL(a, this->_id + "\n" + (msg))\
} while (false)

checks if a is true; prints msg if a is false

Definition at line 406 of file test_system.hpp.

◆ TEST_CHECK_NOT_EQUAL

#define TEST_CHECK_NOT_EQUAL (   a,
  b 
)
Value:
do { \
CHECK_INTERNAL(!((a)==(b)), this->_id + "\n" + "Expected '" #a "' that is'" + FEAT::stringify(a) + "' to equal not '" + FEAT::stringify(b) + "'")\
} while (false)

checks if a != b

Definition at line 380 of file test_system.hpp.

◆ TEST_CHECK_RELATIVE

#define TEST_CHECK_RELATIVE (   a,
  b,
  eps 
)
Value:
do { \
CHECK_INTERNAL(Math::abs((a) - (b)) <= (eps)*Math::abs(b), \
this->_id + "\n" + "Expected '|" #a " - " #b \
"|' <= '" + FEAT::stringify(eps) + "*|" #b "|' = '" + \
FEAT::stringify((eps)*Math::abs(b)) + "' but was '" + \
FEAT::stringify(Math::abs((a) - (b))) + "'" \
+ ", with " #a "=" + FEAT::stringify(a) + " and " #b "=" + FEAT::stringify(b))\
} while (false)

checks if |a - b| <= epsilon*|b|

Definition at line 445 of file test_system.hpp.

◆ TEST_CHECK_STRINGIFY_EQUAL

#define TEST_CHECK_STRINGIFY_EQUAL (   a,
  b 
)
Value:
do { \
String s_a(FEAT::stringify(a)); \
String s_b(FEAT::stringify(b)); \
CHECK_INTERNAL(s_a == s_b, this->_id + "\n" + "Expected '" #a "' to equal '" + s_b + "'\nbut got\n'" + s_a + "'")\
} while (false)

checks if stringify(a) == stringify(b)

Definition at line 392 of file test_system.hpp.

◆ TEST_CHECK_THROWS

#define TEST_CHECK_THROWS (   a,
  b 
)
Value:
do { \
try { \
try { \
a; \
this->check(__func__, __FILE__, __LINE__, false, \
this->_id + "\n" + "Expected exception of type '" #b "' not thrown"); \
} catch (b &) { \
TEST_CHECK(true); \
} \
throw; \
} catch (const std::exception & test_e) { \
throw FEAT::TestSystem::TestFailedException(__func__, __FILE__, __LINE__, \
"Test threw unexpected exception "+ FEAT::stringify(test_e.what()) + \
" inside a TEST_CHECK_THROWS block"); \
} catch (...) { \
throw FEAT::TestSystem::TestFailedException(__func__, __FILE__, __LINE__, \
"Test threw unexpected unknown exception inside a TEST_CHECK_THROWS block"); \
} \
} while (false)

checks if a throws an exception of type b

Definition at line 412 of file test_system.hpp.