mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-26 16:19:30 +03:00
Implement CHECK_ARRAY_CLOSE_DESCRIBED macro
This commit is contained in:
parent
9f0233266b
commit
9d0e5fc35d
3 changed files with 92 additions and 0 deletions
|
|
@ -164,6 +164,10 @@
|
|||
UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, \
|
||||
UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)))
|
||||
|
||||
#define CHECK_ARRAY_CLOSE_DESCRIBED(expected, actual, count, tolerance, description) \
|
||||
UNITTEST_CHECK_ARRAY_CLOSE(expected, actual, count, tolerance, \
|
||||
UNITTEST_CHECK_WITH_DESCRIPTION(UnitTest::ArrayAreClose(expected, actual, count, tolerance), description))
|
||||
|
||||
#define UNITTEST_CHECK_ARRAY_CLOSE(expected, actual, count, tolerance, test_action) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
|
|
|
|||
|
|
@ -742,6 +742,87 @@ TEST(CheckArrayCloseDoesNotHaveSideEffectsWhenFailing)
|
|||
CHECK_EQUAL(1, g_sideEffect);
|
||||
}
|
||||
|
||||
TEST(CheckArrayCloseDescribedSucceedsOnEqual)
|
||||
{
|
||||
bool failure = true;
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
const float data[4] = { 0, 1, 2, 3 };
|
||||
CHECK_ARRAY_CLOSE_DESCRIBED(data, data, 4, 0.01f, "description");
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(!failure);
|
||||
}
|
||||
|
||||
TEST(CheckArrayCloseDescribedFailsOnNotEqual)
|
||||
{
|
||||
bool failure = false;
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
int const data1[4] = { 0, 1, 2, 3 };
|
||||
int const data2[4] = { 0, 1, 3, 3 };
|
||||
CHECK_ARRAY_CLOSE_DESCRIBED(data1, data2, 4, 0.01f, "description");
|
||||
|
||||
failure = (testResults.GetFailureCount() > 0);
|
||||
}
|
||||
|
||||
CHECK(failure);
|
||||
}
|
||||
|
||||
TEST(CheckArrayCloseDescribedFailureContainsCorrectDetails)
|
||||
{
|
||||
int line = 0;
|
||||
RecordingReporter reporter;
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
UnitTest::TestDetails testDetails("arrayCloseTest", "arrayCloseSuite", "filename", -1);
|
||||
ScopedCurrentTest scopedResults(testResults, &testDetails);
|
||||
|
||||
int const data1[4] = { 0, 1, 2, 3 };
|
||||
int const data2[4] = { 0, 1, 3, 3 };
|
||||
CHECK_ARRAY_CLOSE_DESCRIBED(data1, data2, 4, 0.01f, "description " << hex << 0x1234); line = __LINE__;
|
||||
}
|
||||
|
||||
CHECK_EQUAL("arrayCloseTest", reporter.lastFailedTest);
|
||||
CHECK_EQUAL("arrayCloseSuite", reporter.lastFailedSuite);
|
||||
CHECK_EQUAL("filename", reporter.lastFailedFile);
|
||||
CHECK_EQUAL("description 1234", reporter.lastFailedMessage);
|
||||
CHECK_EQUAL(line, reporter.lastFailedLine);
|
||||
}
|
||||
|
||||
TEST(CheckArrayCloseDescribedDoesNotHaveSideEffectsWhenPassing)
|
||||
{
|
||||
g_sideEffect = 0;
|
||||
{
|
||||
UnitTest::TestResults testResults;
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
const float data[] = { 0, 1, 2, 3 };
|
||||
CHECK_ARRAY_CLOSE_DESCRIBED(data, FunctionWithSideEffects2(), 4, 0.01f, "description");
|
||||
}
|
||||
CHECK_EQUAL(1, g_sideEffect);
|
||||
}
|
||||
|
||||
TEST(CheckArrayCloseDescribedDoesNotHaveSideEffectsWhenFailing)
|
||||
{
|
||||
g_sideEffect = 0;
|
||||
{
|
||||
UnitTest::TestResults testResults;
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
|
||||
const float data[] = { 0, 1, 3, 3 };
|
||||
CHECK_ARRAY_CLOSE_DESCRIBED(data, FunctionWithSideEffects2(), 4, 0.01f, "description");
|
||||
}
|
||||
|
||||
CHECK_EQUAL(1, g_sideEffect);
|
||||
}
|
||||
|
||||
TEST(CheckArray2DCloseSucceedsOnEqual)
|
||||
{
|
||||
bool failure = true;
|
||||
|
|
|
|||
|
|
@ -80,6 +80,13 @@ TEST(ArrayCloseSucceeds)
|
|||
CHECK_ARRAY_CLOSE(a1, a2, 3, 0.1f);
|
||||
}
|
||||
|
||||
TEST(CanUseCheckArrayCloseDescribedToGetCustomFailureMessage)
|
||||
{
|
||||
float const x[] = {1, 2.01f, 3};
|
||||
float const expected[] = {1, 2, 3};
|
||||
CHECK_ARRAY_CLOSE_DESCRIBED(expected, x, 3, 0.01f, "x is not correct, have you checked the flux capacitor?");
|
||||
}
|
||||
|
||||
TEST(Array2dCloseSucceeds)
|
||||
{
|
||||
float const a1[][3] = {{1, 2, 3}, {4, 5, 6}};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue