9#include <kernel/backend.hpp> 
   10#include <kernel/util/type_traits.hpp> 
   12#include <kernel/util/math.hpp> 
   24#define CHECK_INTERNAL(was_ok, message)\ 
   26          throw FEAT::TestSystem::TestFailedException(__func__, __FILE__, __LINE__, message); 
   44      : 
public std::exception
 
   71          const char* 
const function,
 
   72          const char* 
const file,
 
   85      virtual const char* 
what() const noexcept
 override 
  111          TestList::_delete(*
_ptr);
 
  122#ifdef FEAT_COMPILER_MICROSOFT 
  123#  pragma warning(push) 
  124#  pragma warning(disable: 4640) 
  130#ifdef FEAT_COMPILER_MICROSOFT 
  137      static void _delete(
TestList * 
const ptr)
 
  164        if (
nullptr == *instance_ptr)
 
  172          if (
nullptr == *instance_ptr)
 
  177        return *instance_ptr;
 
  266      virtual void check(
const char * 
const function, 
const char * 
const file,
 
  267          const long line, 
bool was_ok, 
const String & message)
 const 
  278      virtual void run() 
const = 0;
 
  297      virtual String get_preferred_backend_name()
 const 
  306#define TEST_CHECK_EQUAL(a, b) \ 
  308    CHECK_INTERNAL((a)==(b), this->_id + "\n" +  "Expected '" #a "' to equal \n'" + FEAT::stringify(b) + "'\nbut got\n'" + FEAT::stringify(a) + "'")\
 
  312#define TEST_CHECK_NOT_EQUAL(a, b) \ 
  314    CHECK_INTERNAL(!((a)==(b)), this->_id + "\n" +  "Expected '" #a "' that is'" + FEAT::stringify(a) + "' to equal not '" + FEAT::stringify(b) + "'")\
 
  318#define TEST_CHECK_IN_RANGE(x, a, b) \ 
  320    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) + "]")\
 
  324#define TEST_CHECK_STRINGIFY_EQUAL(a, b) \ 
  326    String s_a(FEAT::stringify(a)); \ 
  327    String s_b(FEAT::stringify(b)); \ 
  328    CHECK_INTERNAL(s_a == s_b, this->_id + "\n" +  "Expected '" #a "' to equal '" + s_b + "'\nbut got\n'" + s_a + "'")\
 
  332#define TEST_CHECK(a) \ 
  334    CHECK_INTERNAL(a, this->_id + "\n" +  "Check '" #a "' failed") \
 
  338#define TEST_CHECK_MSG(a,msg) \ 
  340    CHECK_INTERNAL(a, this->_id + "\n" + (msg))\
 
  344#define TEST_CHECK_THROWS(a, b) \ 
  349        this->check(__func__, __FILE__, __LINE__, false, \ 
  350            this->_id + "\n" +  "Expected exception of type '" #b "' not thrown"); \
 
  354    } catch (const FEAT::TestSystem::TestFailedException &) { \
 
  356    } catch (const std::exception & test_e) { \
 
  357      throw FEAT::TestSystem::TestFailedException(__func__, __FILE__, __LINE__, \
 
  358          "Test threw unexpected exception "+ FEAT::stringify(test_e.what()) + \
 
  359          " inside a TEST_CHECK_THROWS block"); \
 
  361      throw FEAT::TestSystem::TestFailedException(__func__, __FILE__, __LINE__, \
 
  362          "Test threw unexpected unknown exception inside a TEST_CHECK_THROWS block"); \
 
  367#define TEST_CHECK_EQUAL_WITHIN_EPS(a, b, eps) \ 
  369    CHECK_INTERNAL(((a) <= ((b) + (eps))) && ((b) <= ((a) + (eps))), \ 
  370        this->_id + "\n" + "Expected '|" #a " - " #b \
 
  371        "|' <= '" + FEAT::stringify(eps) + "' but was '" + \
 
  372        FEAT::stringify((a) < (b) ? (b) - (a) : (a) - (b)) + "'" \
 
  373        + ", with " #a "=" + FEAT::stringify(a) + " and " #b "=" + FEAT::stringify(b))\
 
  377#define TEST_CHECK_RELATIVE(a, b, eps) \ 
  379    CHECK_INTERNAL(Math::abs((a) - (b)) <= (eps)*Math::abs(b), \ 
  380        this->_id + "\n" + "Expected '|" #a " - " #b \
 
  381        "|' <= '" + FEAT::stringify(eps) + "*|" #b "|' = '" + \
 
  382        FEAT::stringify((eps)*Math::abs(b)) + "' but was '" + \
 
  383        FEAT::stringify(Math::abs((a) - (b))) + "'" \
 
  384        + ", with " #a "=" + FEAT::stringify(a) + " and " #b "=" + FEAT::stringify(b))\
 
  388#define TEST_CHECK_LESS_THAN(a, b) \ 
  390    CHECK_INTERNAL((a) < (b), this->_id + "\n" +  "Expected '" #a "' to be less than \n'" + FEAT::stringify(b) + "'\nbut got\n'" + FEAT::stringify(a) + "'")\
 
  394#define TEST(pre, test, post) \ 
  399    } catch (const FEAT::TestSystem::TestFailedException & test_e) { \ 
String class implementation.
exception thrown by the check method in UnitTest
virtual const char * what() const noexcept override
description
const String _message
failure message
virtual ~TestFailedException() noexcept
DTOR.
TestFailedException(const char *const function, const char *const file, const long line, const String &message)
CTOR.
TestList **const _ptr
Pointer to our managed object.
~DeleteOnDestruction()
Destructor.
DeleteOnDestruction(TestList **const ptr)
Constructor.
list of all instantiated tests
static TestList * instance()
Returns the instance.
std::list< UnitTest * > _tests
internal STL list representation of TestList
static TestList ** _instance_ptr()
Returns a pointer to our instance pointer.
Iterator begin_tests()
returns an iterator to the front of the TestList
std::list< UnitTest * >::iterator Iterator
TestList forward iterator.
void register_test(UnitTest *const test)
adds a test to the TestList
size_t size()
returns the size of the TestList
Iterator erase(Iterator i)
removes iterator target from the TestList
Iterator end_tests()
returns an iterator beyond the last element of the TestList
virtual const String id() const
returns our id string
String _index_name
index type description String
virtual String get_index_name()
returns our target platform
const String _id
test description String
UnitTest(const String &id_in, const String &datatype_name="none", const String &index_name="none", PreferredBackend preferred_backend=PreferredBackend::generic)
CTOR.
virtual void run() const =0
runs the test case
virtual void check(const char *const function, const char *const file, const long line, bool was_ok, const String &message) const
utility method used bei TEST_CHECK_THROWS
virtual String get_datatype_name()
returns our target platform
String _datatype_name
precision description String
PreferredBackend _preferred_backend
preferred compute intensive backend
PreferredBackend
The backend that shall be used in all compute heavy calculations.
String stringify(const T_ &item)
Converts an item into a String.