Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
活的快乐
Third Party Unity
提交
b9b18bf5
T
Third Party Unity
项目概览
活的快乐
/
Third Party Unity
与 Fork 源项目一致
Fork自
OpenHarmony / Third Party Unity
通知
1
Star
0
Fork
0
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
b9b18bf5
编写于
10月 30, 2012
作者:
R
Ross Ryles
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added new asserts to check for plus/minus infinity and NaN.
上级
b14819bc
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
331 addition
and
1 deletion
+331
-1
src/unity.c
src/unity.c
+141
-0
src/unity.h
src/unity.h
+6
-1
src/unity_internals.h
src/unity_internals.h
+36
-0
test/testunity.c
test/testunity.c
+148
-0
未找到文件。
src/unity.c
浏览文件 @
b9b18bf5
...
...
@@ -28,6 +28,9 @@ const char* UnityStrDelta = " Values Not Within Delta ";
const
char
*
UnityStrPointless
=
" You Asked Me To Compare Nothing, Which Was Pointless."
;
const
char
*
UnityStrNullPointerForExpected
=
" Expected pointer to be NULL"
;
const
char
*
UnityStrNullPointerForActual
=
" Actual pointer was NULL"
;
const
char
*
UnityStrInf
=
"Infinity"
;
const
char
*
UnityStrNegInf
=
"Negative Infinity"
;
const
char
*
UnityStrNaN
=
"NaN"
;
// compiler-generic print formatting masks
const
_U_UINT
UnitySizeMask
[]
=
...
...
@@ -595,6 +598,75 @@ void UnityAssertFloatsWithin(const _UF delta,
}
}
//-----------------------------------------------
void
UnityAssertFloatIsInf
(
const
_UF
actual
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
)
{
UNITY_SKIP_EXECUTION
;
if
((
1
.
0
f
/
0
.
0
f
)
!=
actual
)
{
UnityTestResultsFailBegin
(
lineNumber
);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint
(
UnityStrExpected
);
UnityPrint
(
UnityStrInf
);
UnityPrint
(
UnityStrWas
);
UnityPrintFloat
(
actual
);
#else
UnityPrint
(
UnityStrDelta
);
#endif
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
}
}
//-----------------------------------------------
void
UnityAssertFloatIsNegInf
(
const
_UF
actual
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
)
{
UNITY_SKIP_EXECUTION
;
if
((
-
1
.
0
f
/
0
.
0
f
)
!=
actual
)
{
UnityTestResultsFailBegin
(
lineNumber
);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint
(
UnityStrExpected
);
UnityPrint
(
UnityStrNegInf
);
UnityPrint
(
UnityStrWas
);
UnityPrintFloat
(
actual
);
#else
UnityPrint
(
UnityStrDelta
);
#endif
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
}
}
//-----------------------------------------------
void
UnityAssertFloatIsNaN
(
const
_UF
actual
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
)
{
UNITY_SKIP_EXECUTION
;
if
(
actual
==
actual
)
{
UnityTestResultsFailBegin
(
lineNumber
);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint
(
UnityStrExpected
);
UnityPrint
(
UnityStrNaN
);
UnityPrint
(
UnityStrWas
);
UnityPrintFloat
(
actual
);
#else
UnityPrint
(
UnityStrDelta
);
#endif
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
}
}
#endif //not UNITY_EXCLUDE_FLOAT
//-----------------------------------------------
...
...
@@ -690,6 +762,75 @@ void UnityAssertDoublesWithin(const _UD delta,
}
}
//-----------------------------------------------
void
UnityAssertDoubleIsInf
(
const
_UD
actual
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
)
{
UNITY_SKIP_EXECUTION
;
if
((
1
.
0
/
0
.
0
)
!=
actual
)
{
UnityTestResultsFailBegin
(
lineNumber
);
#ifdef UNITY_DOUBLE_VERBOSE
UnityPrint
(
UnityStrExpected
);
UnityPrint
(
UnityStrInf
);
UnityPrint
(
UnityStrWas
);
UnityPrintFloat
((
float
)
actual
);
#else
UnityPrint
(
UnityStrDelta
);
#endif
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
}
}
//-----------------------------------------------
void
UnityAssertDoubleIsNegInf
(
const
_UD
actual
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
)
{
UNITY_SKIP_EXECUTION
;
if
((
-
1
.
0
/
0
.
0
)
!=
actual
)
{
UnityTestResultsFailBegin
(
lineNumber
);
#ifdef UNITY_DOUBLE_VERBOSE
UnityPrint
(
UnityStrExpected
);
UnityPrint
(
UnityStrNegInf
);
UnityPrint
(
UnityStrWas
);
UnityPrintFloat
((
float
)
actual
);
#else
UnityPrint
(
UnityStrDelta
);
#endif
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
}
}
//-----------------------------------------------
void
UnityAssertDoubleIsNaN
(
const
_UD
actual
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
)
{
UNITY_SKIP_EXECUTION
;
if
(
actual
==
actual
)
{
UnityTestResultsFailBegin
(
lineNumber
);
#ifdef UNITY_DOUBLE_VERBOSE
UnityPrint
(
UnityStrExpected
);
UnityPrint
(
UnityStrNaN
);
UnityPrint
(
UnityStrWas
);
UnityPrintFloat
((
float
)
actual
);
#else
UnityPrint
(
UnityStrDelta
);
#endif
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
}
}
#endif // not UNITY_EXCLUDE_DOUBLE
//-----------------------------------------------
...
...
src/unity.h
浏览文件 @
b9b18bf5
...
...
@@ -142,12 +142,17 @@
#define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_FLOAT_IS_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_FLOAT_IS_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_FLOAT_IS_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, NULL)
//Double (If Enabled)
#define TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_DOUBLE(expected, actual) UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, __LINE__, NULL)
#define TEST_ASSERT_DOUBLE_IS_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_DOUBLE_IS_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_DOUBLE_IS_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, NULL)
//-------------------------------------------------------
// Test Asserts (with additional messages)
...
...
src/unity_internals.h
浏览文件 @
b9b18bf5
...
...
@@ -410,6 +410,18 @@ void UnityAssertEqualFloatArray(const _UF* expected,
const
_UU32
num_elements
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
);
void
UnityAssertFloatIsInf
(
const
_UF
actual
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
);
void
UnityAssertFloatIsNegInf
(
const
_UF
actual
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
);
void
UnityAssertFloatIsNaN
(
const
_UF
actual
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
);
#endif
#ifndef UNITY_EXCLUDE_DOUBLE
...
...
@@ -424,6 +436,18 @@ void UnityAssertEqualDoubleArray(const _UD* expected,
const
_UU32
num_elements
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
);
void
UnityAssertDoubleIsInf
(
const
_UD
actual
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
);
void
UnityAssertDoubleIsNegInf
(
const
_UD
actual
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
);
void
UnityAssertDoubleIsNaN
(
const
_UD
actual
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
);
#endif
//-------------------------------------------------------
...
...
@@ -493,20 +517,32 @@ void UnityAssertEqualDoubleArray(const _UD* expected,
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
#else
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#endif
#ifdef UNITY_EXCLUDE_DOUBLE
#define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled")
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled")
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled")
#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled")
#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled")
#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled")
#else
#define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((_UD)(delta), (_UD)(expected), (_UD)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((_UF)(expected) * (_UD)UNITY_DOUBLE_PRECISION, (_UD)expected, (_UD)actual, (UNITY_LINE_TYPE)line, message)
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((_UD*)(expected), (_UD*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), (message), (UNITY_LINE_TYPE)line)
#endif
#endif
test/testunity.c
浏览文件 @
b9b18bf5
...
...
@@ -2325,6 +2325,80 @@ void testFloatsNotEqualPlusMinusInf(void)
#endif
}
void
testFloatIsInf
(
void
)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE
();
#else
TEST_ASSERT_FLOAT_IS_INF
(
2
.
0
f
/
0
.
0
f
);
TEST_ASSERT_FLOAT_IS_NEG_INF
(
-
3
.
0
f
/
0
.
0
f
);
#endif
}
void
testFloatIsNotInf
(
void
)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE
();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_FLOAT_IS_INF
(
2
.
0
f
);
VERIFY_FAILS_END
#endif
}
void
testFloatIsNotNegInf
(
void
)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE
();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_FLOAT_IS_NEG_INF
(
-
999
.
876
f
);
VERIFY_FAILS_END
#endif
}
void
testFloatIsNan
(
void
)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE
();
#else
TEST_ASSERT_FLOAT_IS_NAN
(
0
.
0
f
/
0
.
0
f
);
#endif
}
void
testFloatIsNotNan
(
void
)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE
();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_FLOAT_IS_NAN
(
234
.
9
f
);
VERIFY_FAILS_END
#endif
}
void
testFloatInfIsNotNan
(
void
)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE
();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_FLOAT_IS_NAN
(
1
.
0
f
/
0
.
0
f
);
VERIFY_FAILS_END
#endif
}
void
testFloatNanIsNotInf
(
void
)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE
();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_FLOAT_IS_INF
(
0
.
0
f
/
0
.
0
f
);
VERIFY_FAILS_END
#endif
}
void
testEqualFloatArrays
(
void
)
{
#ifdef UNITY_EXCLUDE_FLOAT
...
...
@@ -2625,6 +2699,80 @@ void testDoublesNotEqualPlusMinusInf(void)
#endif
}
void
testDoubleIsInf
(
void
)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE
();
#else
TEST_ASSERT_DOUBLE_IS_INF
(
2
.
0
f
/
0
.
0
f
);
TEST_ASSERT_DOUBLE_IS_NEG_INF
(
-
3
.
0
f
/
0
.
0
f
);
#endif
}
void
testDoubleIsNotInf
(
void
)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE
();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_DOUBLE_IS_INF
(
2
.
0
f
);
VERIFY_FAILS_END
#endif
}
void
testDoubleIsNotNegInf
(
void
)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE
();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_DOUBLE_IS_NEG_INF
(
-
999
.
876
f
);
VERIFY_FAILS_END
#endif
}
void
testDoubleIsNan
(
void
)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE
();
#else
TEST_ASSERT_DOUBLE_IS_NAN
(
0
.
0
f
/
0
.
0
f
);
#endif
}
void
testDoubleIsNotNan
(
void
)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE
();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_DOUBLE_IS_NAN
(
234
.
9
f
);
VERIFY_FAILS_END
#endif
}
void
testDoubleInfIsNotNan
(
void
)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE
();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_DOUBLE_IS_NAN
(
1
.
0
f
/
0
.
0
f
);
VERIFY_FAILS_END
#endif
}
void
testDoubleNanIsNotInf
(
void
)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE
();
#else
EXPECT_ABORT_BEGIN
TEST_ASSERT_DOUBLE_IS_INF
(
0
.
0
f
/
0
.
0
f
);
VERIFY_FAILS_END
#endif
}
void
testEqualDoubleArrays
(
void
)
{
#ifdef UNITY_EXCLUDE_DOUBLE
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录