Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Unity
提交
25f64173
T
Third Party Unity
项目概览
OpenHarmony
/
Third Party Unity
10 个月 前同步成功
通知
29
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,体验更适合开发者的 AI 搜索 >>
提交
25f64173
编写于
11月 14, 2016
作者:
J
jsalling
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor repeated code to print float expected and actual
Move double tests down in the file
上级
9f4b1a33
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
67 addition
and
82 deletion
+67
-82
src/unity.c
src/unity.c
+17
-32
test/tests/testunity.c
test/tests/testunity.c
+50
-50
未找到文件。
src/unity.c
浏览文件 @
25f64173
...
...
@@ -694,6 +694,19 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
#define UNITY_NAN_CHECK 0
#endif
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
#define UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual) \
do { \
UnityPrint(UnityStrExpected); \
UnityPrintFloat(expected); \
UnityPrint(UnityStrWas); \
UnityPrintFloat(actual); \
} while(0)
#else
#define UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual) \
UnityPrint(UnityStrDelta)
#endif
/* UNITY_EXCLUDE_FLOAT_PRINT */
#ifndef UNITY_EXCLUDE_FLOAT
static
int
UnityFloatsWithin
(
_UF
delta
,
_UF
expected
,
_UF
actual
)
...
...
@@ -729,14 +742,7 @@ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected,
UnityTestResultsFailBegin
(
lineNumber
);
UnityPrint
(
UnityStrElement
);
UnityPrintNumberUnsigned
(
num_elements
-
elements
-
1
);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint
(
UnityStrExpected
);
UnityPrintFloat
(
*
ptr_expected
);
UnityPrint
(
UnityStrWas
);
UnityPrintFloat
(
*
ptr_actual
);
#else
UnityPrint
(
UnityStrDelta
);
#endif
UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT
(
*
ptr_expected
,
*
ptr_actual
);
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
}
...
...
@@ -758,14 +764,7 @@ void UnityAssertFloatsWithin(const _UF delta,
if
(
!
UnityFloatsWithin
(
delta
,
expected
,
actual
))
{
UnityTestResultsFailBegin
(
lineNumber
);
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
UnityPrint
(
UnityStrExpected
);
UnityPrintFloat
(
expected
);
UnityPrint
(
UnityStrWas
);
UnityPrintFloat
(
actual
);
#else
UnityPrint
(
UnityStrDelta
);
#endif
UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT
(
expected
,
actual
);
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
}
...
...
@@ -872,14 +871,7 @@ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected,
UnityTestResultsFailBegin
(
lineNumber
);
UnityPrint
(
UnityStrElement
);
UnityPrintNumberUnsigned
(
num_elements
-
elements
-
1
);
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
UnityPrint
(
UnityStrExpected
);
UnityPrintFloat
(
*
ptr_expected
);
UnityPrint
(
UnityStrWas
);
UnityPrintFloat
(
*
ptr_actual
);
#else
UnityPrint
(
UnityStrDelta
);
#endif
UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT
(
*
ptr_expected
,
*
ptr_actual
);
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
}
...
...
@@ -900,14 +892,7 @@ void UnityAssertDoublesWithin(const _UD delta,
if
(
!
UnityDoublesWithin
(
delta
,
expected
,
actual
))
{
UnityTestResultsFailBegin
(
lineNumber
);
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
UnityPrint
(
UnityStrExpected
);
UnityPrintFloat
(
expected
);
UnityPrint
(
UnityStrWas
);
UnityPrintFloat
(
actual
);
#else
UnityPrint
(
UnityStrDelta
);
#endif
UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT
(
expected
,
actual
);
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
}
...
...
test/tests/testunity.c
浏览文件 @
25f64173
...
...
@@ -3313,56 +3313,6 @@ void testFloatPrintingInfinityAndNaN(void)
#endif
}
void
testDoublePrinting
(
void
)
{
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE
();
#else
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.100469"
,
0
.
10046949999999999
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4294967295.999999"
,
4294967295
.
999999
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4.2949673e+09"
,
4294967295
.
9999995
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4.2949673e+09"
,
4294967296
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.0e+10"
,
9999999995
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9.00719925e+15"
,
9007199254740990
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"7.0e+100"
,
7.0e+100
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"3.0e+200"
,
3.0e+200
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9.23456789e+300"
,
9.23456789e+300
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-0.100469"
,
-
0
.
10046949999999999
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-4294967295.999999"
,
-
4294967295
.
999999
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-4.2949673e+09"
,
-
4294967295
.
9999995
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-7.0e+100"
,
-
7.0e+100
);
#endif
}
void
testDoublePrintingRoundTiesToEven
(
void
)
{
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE
();
#else
#ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.00000001e+10"
,
10000000050
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9.00719925e+15"
,
9007199245000000
.
0
);
#else
/* Default to Round ties to even */
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.0e+10"
,
10000000050
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9.00719924e+15"
,
9007199245000000
.
0
);
#endif
#endif
}
void
testDoublePrintingInfinityAndNaN
(
void
)
{
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE
();
#else
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"Inf"
,
1.7976931348623157e308
*
10
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"Inf"
,
1
.
0
/
d_zero
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-Inf"
,
-
1.7976931348623157e308
*
10
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"NaN"
,
-
1.7976931348623157e308
*
10
.
0
*
d_zero
);
#endif
}
// ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DOUBLE SUPPORT ==================
void
testDoublesWithinDelta
(
void
)
...
...
@@ -3886,6 +3836,56 @@ void testNotEqualDoubleArraysLengthZero(void)
#endif
}
void
testDoublePrinting
(
void
)
{
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE
();
#else
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.100469"
,
0
.
10046949999999999
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4294967295.999999"
,
4294967295
.
999999
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4.2949673e+09"
,
4294967295
.
9999995
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4.2949673e+09"
,
4294967296
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.0e+10"
,
9999999995
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9.00719925e+15"
,
9007199254740990
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"7.0e+100"
,
7.0e+100
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"3.0e+200"
,
3.0e+200
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9.23456789e+300"
,
9.23456789e+300
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-0.100469"
,
-
0
.
10046949999999999
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-4294967295.999999"
,
-
4294967295
.
999999
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-4.2949673e+09"
,
-
4294967295
.
9999995
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-7.0e+100"
,
-
7.0e+100
);
#endif
}
void
testDoublePrintingRoundTiesToEven
(
void
)
{
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE
();
#else
#ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.00000001e+10"
,
10000000050
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9.00719925e+15"
,
9007199245000000
.
0
);
#else
/* Default to Round ties to even */
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.0e+10"
,
10000000050
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9.00719924e+15"
,
9007199245000000
.
0
);
#endif
#endif
}
void
testDoublePrintingInfinityAndNaN
(
void
)
{
#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE
();
#else
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"Inf"
,
1.7976931348623157e308
*
10
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"Inf"
,
1
.
0
/
d_zero
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-Inf"
,
-
1.7976931348623157e308
*
10
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"NaN"
,
-
1.7976931348623157e308
*
10
.
0
*
d_zero
);
#endif
}
// ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DETAIL SUPPORT ==================
void
testThatDetailsCanBeHandleOneDetail
(
void
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录