mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-26 20:38:45 +08:00
Added Unit test macros
CHECK_FLOAT_SAME CHECK_FLOAT_DIFFERENT
This commit is contained in:
parent
3f018ee1a7
commit
344f1b2387
@ -160,6 +160,48 @@
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_FLOAT_SAME(expected, actual) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, 0, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, exc, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream UnitTest_message; \
|
||||
UnitTest_message << "Unhandled exception (" << exc.what() << ") in CHECK_FLOAT_SAME(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
UnitTest_message.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK_FLOAT_SAME(" #expected ", " #actual ")"); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_FLOAT_DIFFERENT(expected, actual) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
UnitTest::CheckNotClose(*UnitTest::CurrentTest::Results(), expected, actual, 0, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, exc, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream UnitTest_message; \
|
||||
UnitTest_message << "Unhandled exception (" << exc.what() << ") in CHECK_FLOAT_DIFFERENT(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
UnitTest_message.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK_FLOAT_DIFFERENT(" #expected ", " #actual ")"); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_ARRAY_EQUAL(expected, actual, count) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
@ -272,6 +314,18 @@
|
||||
#define CHECK_CLOSE(expected, actual, tolerance) UNITTEST_CHECK_CLOSE((expected), (actual), (tolerance))
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_FLOAT_SAME
|
||||
#error CHECK_FLOAT_SAME already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_FLOAT_SAME instead
|
||||
#else
|
||||
#define CHECK_FLOAT_SAME(expected, actual) UNITTEST_CHECK_FLOAT_SAME((expected), (actual))
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_FLOAT_DIFFERENT
|
||||
#error CHECK_FLOAT_DIFFERENT already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_FLOAT_DIFFERENT instead
|
||||
#else
|
||||
#define CHECK_FLOAT_DIFFERENT(expected, actual) UNITTEST_CHECK_FLOAT_DIFFERENT((expected), (actual))
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_ARRAY_EQUAL
|
||||
#error CHECK_ARRAY_EQUAL already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ARRAY_EQUAL instead
|
||||
#else
|
||||
|
||||
@ -265,6 +265,19 @@ namespace UnitTest
|
||||
}
|
||||
}
|
||||
|
||||
template< typename Expected, typename Actual, typename Tolerance >
|
||||
void CheckNotClose(TestResults& results, Expected const& expected, Actual const& actual, Tolerance const& tolerance,
|
||||
TestDetails const& details)
|
||||
{
|
||||
if (AreClose(expected, actual, tolerance))
|
||||
{
|
||||
UnitTest::MemoryOutStream stream;
|
||||
stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual;
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
}
|
||||
}
|
||||
|
||||
template< typename Expected, typename Actual >
|
||||
void CheckArrayEqual(TestResults& results, Expected const& expected, Actual const& actual,
|
||||
size_t const count, TestDetails const& details)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user