1 #ifndef MHO_TestAssertions_HH__
2 #define MHO_TestAssertions_HH__
21 throw std::runtime_error(std::string(__FILE__) + std::string(":") + std::to_string(__LINE__) + std::string(" in ") + \
22 std::string(__PRETTY_FUNCTION__)); \
25 #define HOPS_ASSERT_THROW(test_cond) \
29 throw std::runtime_error(std::string(__FILE__) + std::string(":") + std::to_string(__LINE__) + \
30 std::string(" in ") + std::string(__PRETTY_FUNCTION__)); \
34 #define HOPS_ASSERT_EQUAL(a, b) \
38 throw std::runtime_error(std::string(__FILE__) + std::string(":") + std::to_string(__LINE__) + \
39 std::string(" in ") + std::string(__PRETTY_FUNCTION__) + std::string(": ") + \
40 std::to_string((a)) + std::string(" != ") + std::to_string((b))); \
45 #define HOPS_ASSERT_FLOAT_LESS_THAN(a, b) \
47 std::stringstream ssa; \
49 std::stringstream ssb; \
53 throw std::runtime_error(std::string(__FILE__) + std::string(":") + std::to_string(__LINE__) + \
54 std::string(" in ") + std::string(__PRETTY_FUNCTION__) + std::string(": ") + ssa.str() + \
55 std::string(" !< ") + ssb.str()); \
63 #define REQUIRE(cond) \
68 std::cerr << "FAIL: " #cond " @ " << __FILE__ << ":" << __LINE__ << std::endl; \
76 #define REQUIRE_EQUAL(a, b) \
81 std::stringstream _hops_sa; \
82 std::stringstream _hops_sb; \
85 std::cerr << "FAIL: " #a " == " #b " @ " << __FILE__ << ":" << __LINE__ << " (\"" << _hops_sa.str() << "\" vs \"" \
86 << _hops_sb.str() << "\")" << std::endl; \
93 #define REQUIRE_THROWS(expr) \
96 bool _hops_caught = false; \
101 catch(const std::exception&) \
103 _hops_caught = true; \
107 std::cerr << "FAIL: expected exception from " #expr " @ " << __FILE__ << ":" << __LINE__ << std::endl; \
114 #define CHECK_CLOSE(a, b, tol) \
117 if(std::fabs((a) - (b)) > (tol)) \
119 std::cerr << "FAIL: |" #a " - " #b "| > " #tol " @ " << __FILE__ << ":" << __LINE__ << " (" << (a) << " vs " \
120 << (b) << ")" << std::endl; \
128 #define REQUIRE_CLOSE_CPLX(a, b, tol) \
131 if(std::abs((a) - (b)) > (tol)) \
133 std::cerr << "FAIL: |" #a " - " #b "| > " #tol " @ " << __FILE__ << ":" << __LINE__ \
134 << " (diff=" << std::abs((a) - (b)) << ")" << std::endl; \