Add utils and testlib
This commit is contained in:
58
include/testlib.hpp
Normal file
58
include/testlib.hpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/** @file testlib.hpp
|
||||
*
|
||||
* @author Cory Alexander Balaton (coryab)
|
||||
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
||||
*
|
||||
* @version 1.0
|
||||
*
|
||||
* @brief Function prototypes and macros that are useful.
|
||||
*
|
||||
* This a small testing library that is tailored for the needs of the project.
|
||||
*
|
||||
* @bug No known bugs
|
||||
* */
|
||||
#ifndef __TESTLIB__
|
||||
#define __TESTLIB__
|
||||
|
||||
#include <armadillo>
|
||||
#include <string>
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
/** @def ASSERT(expr)
|
||||
* @brief A prettier assertion function.
|
||||
*
|
||||
* This macro calls the m_assert function which is a more informative
|
||||
* assertion function than the regular assert function from cassert.
|
||||
* */
|
||||
#define ASSERT(expr, msg) \
|
||||
m_assert(expr, #expr, __METHOD_NAME__, __FILE__, __LINE__, msg)
|
||||
|
||||
/** @brief Test an expression, confirm that test is ok, or abort execution.
|
||||
*
|
||||
* @details This function takes in an expression and prints an OK message if
|
||||
* it's true, or it prints a fail message and aborts execution if it fails.
|
||||
*
|
||||
* @param expr The expression to be evaluated
|
||||
* @param expr_str The stringified version of the expression
|
||||
* @param func The function name of the caller
|
||||
* @param file The file of the caller
|
||||
* @param line The line number where this function is called from
|
||||
* @param msg The message to be displayed
|
||||
* */
|
||||
void m_assert(bool expr, std::string expr_str, std::string func,
|
||||
std::string file, int line, std::string msg);
|
||||
|
||||
/** @brief Test if two armadillo vectors are close to each other.
|
||||
*
|
||||
* @details This function takes in 2 vectors and checks if they are
|
||||
* approximately equal to each other given a tolerance.
|
||||
*
|
||||
* @param a Vector a
|
||||
* @param b Vector b
|
||||
* @param tol The tolerance
|
||||
*
|
||||
* @return bool
|
||||
* */
|
||||
bool close_to(arma::vec &a, arma::vec &b, double tol = 1e-8);
|
||||
#endif
|
||||
Reference in New Issue
Block a user