2 Dimensional Ising Model Simulate the change in energy and magnetization in a ferro magnet

Loading...
Searching...
No Matches
testlib.cpp
Go to the documentation of this file.
1
12#include "testlib.hpp"
13
14 namespace details {
15 void m_assert(bool expr, std::string expr_str, std::string f, std::string file,
16 int line, std::string msg)
17{
18 std::function<void(const std::string &)> print_message =
19 [](const std::string &msg) {
20 if (msg.size() > 0) {
21 std::cout << "message: " << msg << "\n\n";
22 }
23 else {
24 std::cout << "\n";
25 }
26 };
27 std::string new_assert(f.size() + (expr ? 4 : 6), '-');
28 std::cout << "\x1B[36m" << new_assert << "\033[0m\n";
29 std::cout << f << ": ";
30 if (expr) {
31 std::cout << "\x1B[32mOK\033[0m\n";
32 print_message(msg);
33 }
34 else {
35 std::cout << "\x1B[31mFAIL\033[0m\n";
36 print_message(msg);
37 std::cout << file << " " << line << ": Assertion \"" << expr_str
38 << "\" Failed\n\n";
39 abort();
40 }
41}
42} // namespace details
testlib.hpp
A small test library.
details::m_assert
void 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.
Definition: testlib.cpp:15