cpp_prac/common/iassert.h
2025-01-11 17:33:06 +01:00

31 lines
1.9 KiB
C++

#include <cassert>
#include <iostream>
#define ASSERT_MSG(cond, msg) \
do { \
if (!(cond)) { \
std::cerr << "Assertion failed: " << msg << "\n"; \
assert(cond); \
} \
} while (0)
#define ASSERT_EQ(expected, actual) \
do { \
if ((expected) != (actual)) { \
std::cerr << "Assertion failed: (" #expected " == " #actual ") " \
<< "Expected: " << (expected) \
<< ", Actual: " << (actual) << "\n"; \
assert((expected) == (actual)); \
} \
} while (0)
#define ASSERT_EQMSG(expected, actual, msg) \
do { \
if ((expected) != (actual)) { \
std::cerr << "Assertion failed: " << msg << "\n" \
<< "(" #expected " == " #actual ") " \
<< "Expected: " << (expected) \
<< ", Actual: " << (actual) << "\n"; \
assert((expected) == (actual)); \
} \
} while (0)