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 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...
 

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.

◆ 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 394 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 332 of file test_system.hpp.

◆ TEST_CHECK_EQUAL

#define TEST_CHECK_EQUAL (   a,
 
)
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:944

checks if a == b

Definition at line 306 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 367 of file test_system.hpp.

◆ TEST_CHECK_IN_RANGE

#define TEST_CHECK_IN_RANGE (   x,
  a,
 
)
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 318 of file test_system.hpp.

◆ TEST_CHECK_LESS_THAN

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

checks if a < b

Definition at line 388 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 338 of file test_system.hpp.

◆ TEST_CHECK_NOT_EQUAL

#define TEST_CHECK_NOT_EQUAL (   a,
 
)
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 312 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 377 of file test_system.hpp.

◆ TEST_CHECK_STRINGIFY_EQUAL

#define TEST_CHECK_STRINGIFY_EQUAL (   a,
 
)
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 324 of file test_system.hpp.

◆ TEST_CHECK_THROWS

#define TEST_CHECK_THROWS (   a,
 
)
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 344 of file test_system.hpp.