test.h File Reference

File containing macros and functions to for main testing. More...

#include <config.h>
#include <QTextStream>
#include <util/random.h>
#include <util/vector.h>

Go to the source code of this file.

Namespaces

namespace  test
 

Namespace containing test facilities.


Defines

#define CHECK(tst)   TEST_RESULT &= test::check(tst, __LINE__, #tst)
#define CHECK_EQUAL(tst, value)   TEST_RESULT &= test::check_equal(tst, value, __LINE__, #tst, #value)
 check if tst is equal to value.
#define CHECK_FLOAT(tst, value, epsilon)   TEST_RESULT &= test::check_float(tst, value, epsilon, __LINE__, #tst, #value)
 Check if tst is equal to value with a relative error of epsilon.
#define CHECK_FLOAT_DIFF(tst, value, epsilon)   TEST_RESULT &= test::check_float_diff(tst, value, epsilon, __LINE__, #tst, #value)
 Check if tst is different to value with a relative error of epsilon.
#define CHECK_NOTEQUAL(tst, value)   TEST_RESULT &= test::check_notequal(tst, value, __LINE__, #tst, #value)
 check if tst is equal to value.
#define CHECK_ZERO(tst, epsilon)   TEST_RESULT &= test::check_zero(tst, epsilon, __LINE__, #tst)
 Check if tst is equal to zero with an error of epsilon.
#define FAILED_FUNCTION(line)   test::out << "Test line " << line << " " << __PRETTY_FUNCTION__ << "() failed as ";
#define FAILED_TEST(line, tst)   test::out << "Test line " << line << " " << tst << " failed as ";
#define TEST_FCT(tst, failed)
 Launch the function test_tst (replacing tst with the argument), expect it to return a boolean and display a message indicating if the test was successful or not.

Functions

bool test::check (bool tst, size_t line_nb, const char *tst_str)
template<typename T1 , typename T2 >
bool test::check_equal (const T1 &tst, const T2 &value, size_t line_nb, const char *tst_str, const char *value_str)
template<typename T1 , typename T2 , typename T3 >
bool test::check_float (const T1 &tst, const T2 &value, const T3 &epsilon, size_t line_nb, const char *tst_str, const char *value_str)
template<typename T1 , typename T2 , typename T3 >
bool test::check_float_diff (const T1 &tst, const T2 &value, const T3 &epsilon, size_t line_nb, const char *tst_str, const char *value_str)
template<typename T1 , typename T2 >
bool test::check_notequal (const T1 &tst, const T2 &value, size_t line_nb, const char *tst_str, const char *value_str)
template<typename T1 , typename T2 >
bool test::check_zero (const T1 &tst, const T2 &epsilon, size_t line_nb, const char *tst_str)
void test::resetResult ()
template<size_t N, typename T >
void test::shuffle (T array[])

Detailed Description

File containing macros and functions to for main testing.

Definition in file test.h.


Define Documentation

#define CHECK_EQUAL ( tst,
value   )     TEST_RESULT &= test::check_equal(tst, value, __LINE__, #tst, #value)

check if tst is equal to value.

The operator == must exist between the two. If not, output the line of the error, show the content of both member (i.e. the output stream operator must exist) and set the variable "TEST_RESULT" to false.

Definition at line 41 of file test.h.

#define CHECK_FLOAT ( tst,
value,
epsilon   )     TEST_RESULT &= test::check_float(tst, value, epsilon, __LINE__, #tst, #value)

Check if tst is equal to value with a relative error of epsilon.

This function is used for floating points number. The absolute epsilon is computed as the relative epsilon multiplied by the biggest absolute values of tst and value;

Definition at line 65 of file test.h.

#define CHECK_FLOAT_DIFF ( tst,
value,
epsilon   )     TEST_RESULT &= test::check_float_diff(tst, value, epsilon, __LINE__, #tst, #value)

Check if tst is different to value with a relative error of epsilon.

This function is used for floating points number. The absolute epsilon is computed as the relative epsilon multiplied by the biggest absolute values of tst and value;

Definition at line 76 of file test.h.

#define CHECK_NOTEQUAL ( tst,
value   )     TEST_RESULT &= test::check_notequal(tst, value, __LINE__, #tst, #value)

check if tst is equal to value.

The operator == must exist between the two. If not, output the line of the error, show the content of both member (i.e. the output stream operator must exist) and set the variable "TEST_RESULT" to false.

Definition at line 54 of file test.h.

#define CHECK_ZERO ( tst,
epsilon   )     TEST_RESULT &= test::check_zero(tst, epsilon, __LINE__, #tst)

Check if tst is equal to zero with an error of epsilon.

This function is used for floating points number.

Definition at line 85 of file test.h.

#define TEST_FCT ( tst,
failed   ) 
Value:
{ \
  bool _11532fd4s85fds_test_failed = !test_##tst(); \
  if(_11532fd4s85fds_test_failed) \
  { \
    failed = true; \
    test::out << #tst " test failed" << endl; \
    setExitCode(10); \
  } \
  else \
    test::out << #tst " test passed" << endl;\
}

Launch the function test_tst (replacing tst with the argument), expect it to return a boolean and display a message indicating if the test was successful or not.

If the test failed, the boolean variable put as second argument is set to true. the variable is not changed otherwise.

Definition at line 98 of file test.h.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:37:53 2013 for VVE by  doxygen 1.6.3