1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-25 09:21:36 +01:00

- fixed floating point comparison

git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@69 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
mvandervoord
2010-04-18 23:25:32 +00:00
parent 54a924571b
commit 12d4d14388
2 changed files with 88 additions and 6 deletions

View File

@@ -334,7 +334,7 @@ void UnityAssertEqualFloatArray(const _UF* expected,
_UU32 elements = num_elements;
const _UF* ptr_expected = expected;
const _UF* ptr_actual = actual;
_UF diff;
_UF diff, tol;
if (elements == 0)
{
@@ -349,7 +349,10 @@ void UnityAssertEqualFloatArray(const _UF* expected,
diff = *ptr_expected - *ptr_actual;
if (diff < 0.0)
diff = 0.0 - diff;
if (diff > (UNITY_FLOAT_PRECISION * *ptr_expected))
tol = UNITY_FLOAT_PRECISION * *ptr_expected;
if (tol < 0.0)
tol = 0.0 - tol;
if (diff > tol)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrElement);

View File

@@ -623,6 +623,34 @@ void testFloatsNotEqual(void)
VERIFY_FAILURE_WAS_CAUGHT
}
void testFloatsNotEqualNegative1(void)
{
int failed;
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT(-9273.9649f, -9273.0049f);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
VERIFY_FAILURE_WAS_CAUGHT
}
void testFloatsNotEqualNegative2(void)
{
int failed;
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT(-9273.0049f, -9273.9649f);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
VERIFY_FAILURE_WAS_CAUGHT
}
void testIntsWithinDelta(void)
{
TEST_ASSERT_INT_WITHIN(1, 5000, 5001);
@@ -1252,10 +1280,10 @@ void testNotEqualHEX8Arrays3(void)
void testEqualFloatArrays(void)
{
float p0[] = {1.0, 8.0, 25.4, 0.123};
float p1[] = {1.0, 8.0, 25.4, 0.123};
float p2[] = {1.0, 8.0, 25.4, 0.2};
float p3[] = {1.0, 23.0, 25.0, 0.26};
float p0[] = {1.0, -8.0, 25.4, -0.123};
float p1[] = {1.0, -8.0, 25.4, -0.123};
float p2[] = {1.0, -8.0, 25.4, -0.2};
float p3[] = {1.0, -23.0, 25.0, -0.26};
TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p0, 1);
TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p0, 4);
@@ -1315,6 +1343,57 @@ void testNotEqualFloatArrays3(void)
VERIFY_FAILURE_WAS_CAUGHT
}
void testNotEqualFloatArraysNegative1(void)
{
float p0[] = {-1.0, -8.0, -25.4, -0.253};
float p1[] = {-1.0, -8.0, -25.4, -0.252};
int failed;
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
VERIFY_FAILURE_WAS_CAUGHT
}
void testNotEqualFloatArraysNegative2(void)
{
float p0[] = {-1.0, -8.0, -25.4, -0.253};
float p1[] = {-2.0, -8.0, -25.4, -0.253};
int failed;
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
VERIFY_FAILURE_WAS_CAUGHT
}
void testNotEqualFloatArraysNegative3(void)
{
float p0[] = {-1.0, -8.0, -25.4, -0.253};
float p1[] = {-1.0, -8.0, -25.5, -0.253};
int failed;
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
VERIFY_FAILURE_WAS_CAUGHT
}
void testEqualMemoryArrays(void)
{
int p0[] = {1, 8, 987, -2};