Test macros: be more rigorous and consistent

- Because of possible operator overloading, make SG_CHECK_EQUAL(a, b)
  fail if, and only if (a) == (b) is false (testing if (a) != (b) for
  this macro is not correct in general).

- For clarity and consistency, change the messages printed when some
  tests fail: SG_VERIFY(some_test) prints 'failed: some_test' (okay),
  but SG_CHECK_EQUAL(a, b) used to print 'failed: a != b', which is
  inconsistent. Instead, print: 'failed: a == b' because this is what we
  know that failed (again, because of possible operator overloading,
  pretending we know the the logical value of (a != b) after testing
  (a == b) is not correct in general.

  Similarly, the "approximate equality tests" SG_CHECK_EQUAL_EP() and
  SG_CHECK_EQUAL_EP2() now print something like 'failed: a ~= b' when
  they fail, instead of 'failed with epsilon: a != b'.
This commit is contained in:
Florent Rougon 2016-12-04 16:13:50 +01:00
parent ab4814c916
commit b4178ae888

View File

@ -13,8 +13,8 @@
}
#define SG_CHECK_EQUAL(a, b) \
if ((a) != (b)) { \
std::cerr << "failed: " << #a << " != " << #b << std::endl; \
if ( !((a) == (b)) ) { \
std::cerr << "failed: " << #a << " == " << #b << std::endl; \
std::cerr << "\tgot '" << a << "' and '" << b << "'" << std::endl; \
std::cerr << "\tat " << __FILE__ << ":" << __LINE__ << std::endl; \
exit(1); \
@ -22,7 +22,7 @@
#define SG_CHECK_EQUAL_EP(a, b) \
if (std::fabs((a) - (b)) > SG_EPSILON) { \
std::cerr << "failed with epsilon: " << #a << " != " << #b << std::endl; \
std::cerr << "failed: " << #a << " ~= " << #b << std::endl; \
std::cerr << "\tgot '" << a << "' and '" << b << "'" << std::endl; \
std::cerr << "\tat " << __FILE__ << ":" << __LINE__ << std::endl; \
exit(1); \
@ -30,7 +30,7 @@
#define SG_CHECK_EQUAL_EP2(a, b, ep) \
if (std::fabs((a) - (b)) > ep) { \
std::cerr << "failed with epsilon: " << #a << " != " << #b << std::endl; \
std::cerr << "failed: " << #a << " ~= " << #b << std::endl; \
std::cerr << "\tgot '" << a << "' and '" << b << "'" << std::endl; \
std::cerr << "\tat " << __FILE__ << ":" << __LINE__ << std::endl; \
exit(1); \