Simulating the Schrödinger wave equation using the Crank-Nicolson method in 2+1 dimensions
Simulating the Schrödinger wave equation using the Crank-Nicolson method in 2+1 dimensions
Loading...
Searching...
No Matches
testlib.hpp File Reference

A small test library. More...

#include "utils.hpp"
#include <armadillo>
#include <string>
#include <type_traits>

Go to the source code of this file.

Macros

#define ASSERT(expr, msg)    details::m_assert(expr, #expr, __METHOD_NAME__, __FILE__, __LINE__, msg)
 A prettier assertion function.
 

Functions

void details::m_assert (bool expr, std::string expr_str, std::string func, std::string file, int line, std::string msg)
 Test an expression, confirm that test is ok, or abort execution.
 
template<class T , class = typename std::enable_if<std::is_arithmetic<T>::value>::type>
static bool testlib::close_to (arma::Mat< T > &a, arma::Mat< T > &b, double tol=1e-8)
 Test if two armadillo matrices/vectors are close to each other.
 
template<class T , class = typename std::enable_if<std::is_arithmetic<T>::value>::type>
static bool testlib::close_to (T a, T b, double tol=1e-8)
 Test if two numbers are close to each other.
 
template<class T , class = typename std::enable_if<std::is_integral<T>::value>::type>
static bool testlib::is_equal (arma::Mat< T > &a, arma::Mat< T > &b)
 Test if two armadillo matrices/vectors are equal.
 
template<class T , class = typename std::enable_if<std::is_arithmetic<T>::value>::type>
static bool testlib::assert_each (std::function< bool(T)> expr, arma::Mat< T > &M)
 Test that all elements fulfill the condition.
 

Detailed Description

A small test library.

Author
Cory Alexander Balaton (coryab)
Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
1.0

This a small testing library that is tailored for the needs of the project. Anything that is in the details namespace should not be used directly, or else it might cause undefined behavior if not used correctly.

Bug:
No known bugs

Definition in file testlib.hpp.

Macro Definition Documentation

◆ ASSERT

#define ASSERT (   expr,
  msg 
)     details::m_assert(expr, #expr, __METHOD_NAME__, __FILE__, __LINE__, msg)

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.

Definition at line 31 of file testlib.hpp.

Function Documentation

◆ assert_each()

template<class T , class = typename std::enable_if<std::is_arithmetic<T>::value>::type>
static bool testlib::assert_each ( std::function< bool(T)>  expr,
arma::Mat< T > &  M 
)
static

Test that all elements fulfill the condition.

Parameters
exprThe boolean expression to apply to each element
MThe matrix/vector to iterate over
Returns
bool

Definition at line 130 of file testlib.hpp.

◆ close_to() [1/2]

template<class T , class = typename std::enable_if<std::is_arithmetic<T>::value>::type>
static bool testlib::close_to ( arma::Mat< T > &  a,
arma::Mat< T > &  b,
double  tol = 1e-8 
)
static

Test if two armadillo matrices/vectors are close to each other.

This function takes in 2 matrices/vectors and checks if they are approximately equal to each other given a tolerance.

Parameters
aMatrix/vector a
bMatrix/vector b
tolThe tolerance
Returns
bool

Definition at line 67 of file testlib.hpp.

◆ close_to() [2/2]

template<class T , class = typename std::enable_if<std::is_arithmetic<T>::value>::type>
static bool testlib::close_to ( a,
b,
double  tol = 1e-8 
)
static

Test if two numbers are close to each other.

This function takes in 2 matrices/vectors and checks if they are approximately equal to each other given a tolerance.

Parameters
aMatrix/vector a
bMatrix/vector b
tolThe tolerance
Returns
bool

Definition at line 94 of file testlib.hpp.

◆ is_equal()

template<class T , class = typename std::enable_if<std::is_integral<T>::value>::type>
static bool testlib::is_equal ( arma::Mat< T > &  a,
arma::Mat< T > &  b 
)
static

Test if two armadillo matrices/vectors are equal.

This function takes in 2 matrices/vectors and checks if they are equal to each other. This should only be used for integral types.

Parameters
aMatrix/vector a
bMatrix/vector b
Returns
bool

Definition at line 111 of file testlib.hpp.

◆ m_assert()

void details::m_assert ( bool  expr,
std::string  expr_str,
std::string  func,
std::string  file,
int  line,
std::string  msg 
)

Test an expression, confirm that test is ok, or abort execution.

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.

Parameters
exprThe expression to be evaluated
expr_strThe stringified version of the expression
funcThe function name of the caller
fileThe file of the caller
lineThe line number where this function is called from
msgThe message to be displayed