ModErn Text Analysis
META Enumerates Textual Applications
Classes | Namespaces | Macros | Functions
unit_test.h File Reference
#include <cmath>
#include <iomanip>
#include <string>
#include <functional>
#include <iostream>
#include "util/printing.h"

Go to the source code of this file.

Classes

class  meta::testing::unit_test_exception
 Exception class used to report errors in the unit test. More...
 

Namespaces

 meta
 The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
 
 meta::testing
 Contains unit testing functions for the META toolkit.
 

Macros

#define ASSERT(expr)
 Fail if expr is false; otherwise continue. More...
 
#define ASSERT_EQUAL(exp1, exp2)
 Fail if exp1 != exp2; otherwise continue. More...
 
#define ASSERT_APPROX_EQUAL(exp1, exp2)
 Fail if !(|exp1 - exp2| < epsilon); otherwise continue. More...
 
#define ASSERT_BINOP(exp1, exp2, binop)
 Fail if !binop(exp1, exp2). More...
 
#define FAIL(why)
 Fail this test case with an explanation. More...
 
#define ASSERT_LESS(exp1, exp2)
 Fail if !(exp1 < exp2) More...
 
#define ASSERT_GREATER(exp1, exp2)
 Fail if !(exp1 > exp2) More...
 

Functions

std::string meta::testing::filename (const std::string &path)
 
template<class T , class K , class BinOp >
std::string meta::testing::assert_equal (const T &expected, const K &actual, const char *expstr, const char *actstr, BinOp &&binop)
 Allows the user to see what the evaluated statements are. More...
 
template<class T , class K >
std::string meta::testing::assert_equal (const T &expected, const K &actual, const char *expstr, const char *actstr)
 
template<class T , class K >
std::string meta::testing::assert_approx_equal (const T &expected, const K &actual, const char *expstr, const char *actstr)
 
template<class T , class K >
std::string meta::testing::assert_less (const T &expected, const K &actual, const char *expstr, const char *actstr)
 
template<class T , class K >
std::string meta::testing::assert_greater (const T &expected, const K &actual, const char *expstr, const char *actstr)
 
template<class Func >
int meta::testing::run_test (const std::string &test_name, Func &&func)
 Runs a unit test in a semi-controlled environment. More...
 

Detailed Description

Author
Sean Massung

All files in META are dual-licensed under the MIT and NCSA licenses. For more details, consult the file LICENSE.mit and LICENSE.ncsa in the root of the project.

Macro Definition Documentation

#define ASSERT (   expr)
Value:
do \
{ \
if (!(expr)) \
FAIL("Assertion failed: " #expr); \
} while (0)
#define FAIL(why)
Fail this test case with an explanation.
Definition: unit_test.h:69

Fail if expr is false; otherwise continue.

#define ASSERT_EQUAL (   exp1,
  exp2 
)
Value:
do \
{ \
std::string msg = testing::assert_equal(exp1, exp2, #exp1, #exp2); \
if (!msg.empty()) \
FAIL(msg); \
} while (0)
#define FAIL(why)
Fail this test case with an explanation.
Definition: unit_test.h:69
std::string assert_equal(const T &expected, const K &actual, const char *expstr, const char *actstr)
Definition: unit_test.h:153

Fail if exp1 != exp2; otherwise continue.

See also
https://bitbucket.org/jacktoole1/monad_hg/ for string printing
#define ASSERT_APPROX_EQUAL (   exp1,
  exp2 
)
Value:
do \
{ \
std::string msg \
= testing::assert_approx_equal(exp1, exp2, #exp1, #exp2); \
if (!msg.empty()) \
FAIL(msg); \
} while (0)
#define FAIL(why)
Fail this test case with an explanation.
Definition: unit_test.h:69
std::string assert_approx_equal(const T &expected, const K &actual, const char *expstr, const char *actstr)
Definition: unit_test.h:170

Fail if !(|exp1 - exp2| < epsilon); otherwise continue.

#define ASSERT_BINOP (   exp1,
  exp2,
  binop 
)
Value:
do \
{ \
std::string msg = testing::assert(exp1, exp2, #exp1, #exp2, binop); \
if (!msg.empty()) \
FAIL(msg); \
} while (0)
#define FAIL(why)
Fail this test case with an explanation.
Definition: unit_test.h:69

Fail if !binop(exp1, exp2).

#define FAIL (   why)
Value:
do \
{ \
std::string fail_msg = "[ " + printing::make_red("FAIL") + " ] " \
+ (why) + " (" + testing::filename(__FILE__) \
+ ":" + std::to_string(__LINE__) + ")"; \
throw testing::unit_test_exception{fail_msg}; \
} while (0)
std::string make_red(std::string str)
Definition: printing.h:53
std::string filename(const std::string &path)
Definition: unit_test.h:114

Fail this test case with an explanation.

Give line number and file where the test case failed.

#define ASSERT_LESS (   exp1,
  exp2 
)
Value:
do \
{ \
std::string msg = testing::assert_less(exp1, exp2, #exp1, #exp2); \
if (!msg.empty()) \
FAIL(msg); \
} while (0)
#define FAIL(why)
Fail this test case with an explanation.
Definition: unit_test.h:69
std::string assert_less(const T &expected, const K &actual, const char *expstr, const char *actstr)
Definition: unit_test.h:190

Fail if !(exp1 < exp2)

#define ASSERT_GREATER (   exp1,
  exp2 
)
Value:
do \
{ \
std::string msg = testing::assert_greater(exp1, exp2, #exp1, #exp2); \
if (!msg.empty()) \
FAIL(msg); \
} while (0)
std::string assert_greater(const T &expected, const K &actual, const char *expstr, const char *actstr)
Definition: unit_test.h:210
#define FAIL(why)
Fail this test case with an explanation.
Definition: unit_test.h:69

Fail if !(exp1 > exp2)