Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Unity
提交
7dc17efb
T
Third Party Unity
项目概览
OpenHarmony
/
Third Party Unity
大约 1 年 前同步成功
通知
34
Star
144
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Unity
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7dc17efb
编写于
9月 21, 2016
作者:
M
Mark VanderVoord
提交者:
GitHub
9月 21, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #215 from jsalling/bugfix/inf-equals-inf
Bugfix Inf equals Inf
上级
71f2e0e6
41c2e588
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
61 addition
and
95 deletion
+61
-95
release/version.info
release/version.info
+1
-1
src/unity.c
src/unity.c
+26
-60
src/unity_internals.h
src/unity_internals.h
+29
-21
test/tests/testunity.c
test/tests/testunity.c
+5
-13
未找到文件。
release/version.info
浏览文件 @
7dc17efb
2.3.
2
2.3.
3
src/unity.c
浏览文件 @
7dc17efb
...
...
@@ -52,12 +52,6 @@ static const char UnityStrResultsIgnored[] = " Ignored ";
static
const
char
UnityStrDetail1Name
[]
=
UNITY_DETAIL1_NAME
" "
;
static
const
char
UnityStrDetail2Name
[]
=
" "
UNITY_DETAIL2_NAME
" "
;
#ifdef UNITY_FLOAT_NEEDS_ZERO
/* Dividing by these constants produces +/- infinity.
* The rationale is given in UnityAssertFloatIsInf's body. */
static
const
_UF
f_zero
=
0
.
0
f
;
#endif
/* compiler-generic print formatting masks */
static
const
_U_UINT
UnitySizeMask
[]
=
{
...
...
@@ -265,7 +259,7 @@ void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
# endif
#endif
void
UnityPrintFloat
(
_U
F
number
)
void
UnityPrintFloat
(
_U
D
number
)
{
char
TempBuffer
[
UNITY_VERBOSE_NUMBER_MAX_LENGTH
+
1
];
snprintf
(
TempBuffer
,
sizeof
(
TempBuffer
),
"%.6f"
,
number
);
...
...
@@ -620,7 +614,22 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
}
/*-----------------------------------------------*/
/* Wrap this define in a function with variable types as float or double */
#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
if (expected == actual) return 1; \
diff = actual - expected; \
if (diff < 0.0f) diff = 0.0f - diff; \
if (delta < 0.0f) delta = 0.0f - delta; \
return !(isnan(diff) || isinf(diff) || (delta < diff));
/* This first part of this condition will catch any NaN or Infinite values */
#ifndef UNITY_EXCLUDE_FLOAT
static
int
UnityFloatsWithin
(
_UF
delta
,
_UF
expected
,
_UF
actual
)
{
_UF
diff
;
UNITY_FLOAT_OR_DOUBLE_WITHIN
(
delta
,
expected
,
actual
,
diff
);
}
void
UnityAssertEqualFloatArray
(
UNITY_PTR_ATTRIBUTE
const
_UF
*
expected
,
UNITY_PTR_ATTRIBUTE
const
_UF
*
actual
,
const
_UU32
num_elements
,
...
...
@@ -630,7 +639,6 @@ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected,
_UU32
elements
=
num_elements
;
UNITY_PTR_ATTRIBUTE
const
_UF
*
ptr_expected
=
expected
;
UNITY_PTR_ATTRIBUTE
const
_UF
*
ptr_actual
=
actual
;
_UF
diff
,
tol
;
UNITY_SKIP_EXECUTION
;
...
...
@@ -644,15 +652,7 @@ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected,
while
(
elements
--
)
{
diff
=
*
ptr_expected
-
*
ptr_actual
;
if
(
diff
<
0
.
0
f
)
diff
=
0
.
0
f
-
diff
;
tol
=
UNITY_FLOAT_PRECISION
*
*
ptr_expected
;
if
(
tol
<
0
.
0
f
)
tol
=
0
.
0
f
-
tol
;
/* This first part of this condition will catch any NaN or Infinite values */
if
(
isnan
(
diff
)
||
isinf
(
diff
)
||
(
diff
>
tol
))
if
(
!
UnityFloatsWithin
(
*
ptr_expected
*
UNITY_FLOAT_PRECISION
,
*
ptr_expected
,
*
ptr_actual
))
{
UnityTestResultsFailBegin
(
lineNumber
);
UnityPrint
(
UnityStrElement
);
...
...
@@ -680,22 +680,10 @@ void UnityAssertFloatsWithin(const _UF delta,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
)
{
_UF
diff
=
actual
-
expected
;
_UF
pos_delta
=
delta
;
UNITY_SKIP_EXECUTION
;
if
(
diff
<
0
.
0
f
)
{
diff
=
0
.
0
f
-
diff
;
}
if
(
pos_delta
<
0
.
0
f
)
{
pos_delta
=
0
.
0
f
-
pos_delta
;
}
/* This first part of this condition will catch any NaN or Infinite values */
if
(
isnan
(
diff
)
||
isinf
(
diff
)
||
(
pos_delta
<
diff
))
if
(
!
UnityFloatsWithin
(
delta
,
expected
,
actual
))
{
UnityTestResultsFailBegin
(
lineNumber
);
#ifdef UNITY_FLOAT_VERBOSE
...
...
@@ -726,8 +714,6 @@ void UnityAssertFloatSpecial(const _UF actual,
switch
(
style
)
{
/* To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly
* We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise */
case
UNITY_FLOAT_IS_INF
:
case
UNITY_FLOAT_IS_NOT_INF
:
is_trait
=
isinf
(
actual
)
&
ispos
(
actual
);
...
...
@@ -737,7 +723,6 @@ void UnityAssertFloatSpecial(const _UF actual,
is_trait
=
isinf
(
actual
)
&
isneg
(
actual
);
break
;
/* NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN. */
case
UNITY_FLOAT_IS_NAN
:
case
UNITY_FLOAT_IS_NOT_NAN
:
is_trait
=
isnan
(
actual
);
...
...
@@ -782,6 +767,12 @@ void UnityAssertFloatSpecial(const _UF actual,
/*-----------------------------------------------*/
#ifndef UNITY_EXCLUDE_DOUBLE
static
int
UnityDoublesWithin
(
_UD
delta
,
_UD
expected
,
_UD
actual
)
{
_UD
diff
;
UNITY_FLOAT_OR_DOUBLE_WITHIN
(
delta
,
expected
,
actual
,
diff
);
}
void
UnityAssertEqualDoubleArray
(
UNITY_PTR_ATTRIBUTE
const
_UD
*
expected
,
UNITY_PTR_ATTRIBUTE
const
_UD
*
actual
,
const
_UU32
num_elements
,
...
...
@@ -791,7 +782,6 @@ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected,
_UU32
elements
=
num_elements
;
UNITY_PTR_ATTRIBUTE
const
_UD
*
ptr_expected
=
expected
;
UNITY_PTR_ATTRIBUTE
const
_UD
*
ptr_actual
=
actual
;
_UD
diff
,
tol
;
UNITY_SKIP_EXECUTION
;
...
...
@@ -805,15 +795,7 @@ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected,
while
(
elements
--
)
{
diff
=
*
ptr_expected
-
*
ptr_actual
;
if
(
diff
<
0
.
0
)
diff
=
0
.
0
-
diff
;
tol
=
UNITY_DOUBLE_PRECISION
*
*
ptr_expected
;
if
(
tol
<
0
.
0
)
tol
=
0
.
0
-
tol
;
/* This first part of this condition will catch any NaN or Infinite values */
if
(
isnan
(
diff
)
||
isinf
(
diff
)
||
(
diff
>
tol
))
if
(
!
UnityDoublesWithin
(
*
ptr_expected
*
UNITY_DOUBLE_PRECISION
,
*
ptr_expected
,
*
ptr_actual
))
{
UnityTestResultsFailBegin
(
lineNumber
);
UnityPrint
(
UnityStrElement
);
...
...
@@ -841,22 +823,9 @@ void UnityAssertDoublesWithin(const _UD delta,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
)
{
_UD
diff
=
actual
-
expected
;
_UD
pos_delta
=
delta
;
UNITY_SKIP_EXECUTION
;
if
(
diff
<
0
.
0
)
{
diff
=
0
.
0
-
diff
;
}
if
(
pos_delta
<
0
.
0
)
{
pos_delta
=
0
.
0
-
pos_delta
;
}
/* This first part of this condition will catch any NaN or Infinite values */
if
(
isnan
(
diff
)
||
isinf
(
diff
)
||
(
pos_delta
<
diff
))
if
(
!
UnityDoublesWithin
(
delta
,
expected
,
actual
))
{
UnityTestResultsFailBegin
(
lineNumber
);
#ifdef UNITY_DOUBLE_VERBOSE
...
...
@@ -888,8 +857,6 @@ void UnityAssertDoubleSpecial(const _UD actual,
switch
(
style
)
{
/* To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly
* We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise */
case
UNITY_FLOAT_IS_INF
:
case
UNITY_FLOAT_IS_NOT_INF
:
is_trait
=
isinf
(
actual
)
&
ispos
(
actual
);
...
...
@@ -899,7 +866,6 @@ void UnityAssertDoubleSpecial(const _UD actual,
is_trait
=
isinf
(
actual
)
&
isneg
(
actual
);
break
;
/* NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN. */
case
UNITY_FLOAT_IS_NAN
:
case
UNITY_FLOAT_IS_NOT_NAN
:
is_trait
=
isnan
(
actual
);
...
...
src/unity_internals.h
浏览文件 @
7dc17efb
...
...
@@ -189,11 +189,13 @@
typedef
UNITY_FLOAT_TYPE
_UF
;
#ifndef isinf
#define isinf(n) (((1.0f / f_zero) == n) ? 1 : 0) || (((-1.0f / f_zero) == n) ? 1 : 0)
#define
UNITY_FLOAT_NEEDS_ZERO
/* The value of Inf - Inf is NaN */
#define
isinf(n) (isnan((n) - (n)) && !isnan(n))
#endif
#ifndef isnan
/* NaN is the only floating point value that does NOT equal itself.
* Therefore if n != n, then it is NaN. */
#define isnan(n) ((n != n) ? 1 : 0)
#endif
...
...
@@ -213,32 +215,38 @@ typedef UNITY_FLOAT_TYPE _UF;
/* unlike FLOAT, we DON'T include by default */
#ifndef UNITY_EXCLUDE_DOUBLE
#ifndef UNITY_INCLUDE_DOUBLE
#define UNITY_EXCLUDE_DOUBLE
#endif
#ifndef UNITY_INCLUDE_DOUBLE
#define UNITY_EXCLUDE_DOUBLE
#endif
#endif
#ifdef UNITY_EXCLUDE_DOUBLE
/* No Floating Point Support */
#undef UNITY_DOUBLE_PRECISION
#undef UNITY_DOUBLE_TYPE
#undef UNITY_DOUBLE_VERBOSE
/* No Floating Point Support */
#undef UNITY_DOUBLE_PRECISION
#undef UNITY_DOUBLE_TYPE
#undef UNITY_DOUBLE_VERBOSE
#ifdef UNITY_INCLUDE_DOUBLE
#undef UNITY_INCLUDE_DOUBLE
#endif
#ifdef UNITY_INCLUDE_DOUBLE
#undef UNITY_INCLUDE_DOUBLE
#endif
#ifdef UNITY_FLOAT_VERBOSE
typedef
_UF
_UD
;
/* For parameter in UnityPrintFloat, double promotion required */
#endif
#else
/* Double Floating Point Support */
#ifndef UNITY_DOUBLE_PRECISION
#define UNITY_DOUBLE_PRECISION (1e-12f)
#endif
#ifndef UNITY_DOUBLE_TYPE
#define UNITY_DOUBLE_TYPE double
#endif
typedef
UNITY_DOUBLE_TYPE
_UD
;
/* Double Floating Point Support */
#ifndef UNITY_DOUBLE_PRECISION
#define UNITY_DOUBLE_PRECISION (1e-12f)
#endif
#ifndef UNITY_DOUBLE_TYPE
#define UNITY_DOUBLE_TYPE double
#endif
typedef
UNITY_DOUBLE_TYPE
_UD
;
#endif
...
...
@@ -436,7 +444,7 @@ void UnityPrintNumberUnsigned(const _U_UINT number);
void
UnityPrintNumberHex
(
const
_U_UINT
number
,
const
char
nibbles
);
#ifdef UNITY_FLOAT_VERBOSE
void
UnityPrintFloat
(
const
_U
F
number
);
void
UnityPrintFloat
(
const
_U
D
number
);
#endif
/*-------------------------------------------------------
...
...
test/tests/testunity.c
浏览文件 @
7dc17efb
...
...
@@ -4,8 +4,8 @@
[Released under MIT License. Please refer to license.txt for details]
========================================== */
#include <setjmp.h>
#include "unity.h"
#include <setjmp.h>
#include <string.h>
// Dividing by these constants produces +/- infinity.
...
...
@@ -2852,14 +2852,12 @@ void testFloatsNotEqualExpectedInf(void)
#endif
}
void
testFloats
Not
EqualBothInf
(
void
)
void
testFloatsEqualBothInf
(
void
)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE
();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT
(
1
.
0
f
/
f_zero
,
1
.
0
f
/
f_zero
);
VERIFY_FAILS_END
#endif
}
...
...
@@ -3208,7 +3206,7 @@ void testNotEqualFloatArraysNaN(void)
#endif
}
void
test
Not
EqualFloatArraysInf
(
void
)
void
testEqualFloatArraysInf
(
void
)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE
();
...
...
@@ -3216,9 +3214,7 @@ void testNotEqualFloatArraysInf(void)
float
p0
[]
=
{
1
.
0
f
,
1
.
0
f
/
f_zero
,
25
.
4
f
,
0
.
253
f
};
float
p1
[]
=
{
1
.
0
f
,
1
.
0
f
/
f_zero
,
25
.
4
f
,
0
.
253
f
};
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT_ARRAY
(
p0
,
p1
,
4
);
VERIFY_FAILS_END
#endif
}
...
...
@@ -3384,14 +3380,12 @@ void testDoublesNotEqualExpectedInf(void)
#endif
}
void
testDoubles
Not
EqualBothInf
(
void
)
void
testDoublesEqualBothInf
(
void
)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE
();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_DOUBLE
(
1
.
0
/
d_zero
,
1
.
0
/
d_zero
);
VERIFY_FAILS_END
#endif
}
...
...
@@ -3739,7 +3733,7 @@ void testNotEqualDoubleArraysNaN(void)
#endif
}
void
test
Not
EqualDoubleArraysInf
(
void
)
void
testEqualDoubleArraysInf
(
void
)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE
();
...
...
@@ -3747,9 +3741,7 @@ void testNotEqualDoubleArraysInf(void)
double
p0
[]
=
{
1
.
0
,
1
.
0
/
d_zero
,
25
.
4
,
0
.
253
};
double
p1
[]
=
{
1
.
0
,
1
.
0
/
d_zero
,
25
.
4
,
0
.
253
};
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_DOUBLE_ARRAY
(
p0
,
p1
,
4
);
VERIFY_FAILS_END
#endif
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录