Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
活的快乐
Third Party Unity
提交
9f4b1a33
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,发现更多精彩内容 >>
提交
9f4b1a33
编写于
11月 14, 2016
作者:
J
jsalling
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tests for Printing Floating Point numbers
上级
47f6a85b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
84 addition
and
13 deletion
+84
-13
src/unity.c
src/unity.c
+1
-1
test/tests/testunity.c
test/tests/testunity.c
+83
-12
未找到文件。
src/unity.c
浏览文件 @
9f4b1a33
...
...
@@ -297,7 +297,7 @@ void UnityPrintFloat(_UD number)
/* Double precision calculation gives best performance for six rounded decimal places */
ROUND_TIES_TO_EVEN
(
fraction_part
,
(
number
-
integer_part
)
*
1000000
.
0
);
if
(
fraction_part
==
1000000
)
if
(
fraction_part
==
1000000
)
/* Carry across the decimal point */
{
fraction_part
=
0
;
integer_part
+=
1
;
...
...
test/tests/testunity.c
浏览文件 @
9f4b1a33
...
...
@@ -7,6 +7,7 @@
#include "unity.h"
#include <setjmp.h>
#include <string.h>
#include <stdint.h>
// Dividing by these constants produces +/- infinity.
// The rationale is given in UnityAssertFloatIsInf's body.
...
...
@@ -2237,7 +2238,7 @@ void testIgnoredAndThenFailInTearDown(void)
#endif
#ifdef USING_OUTPUT_SPY
#include <stdio.h>
int
putchar
(
int
);
#define SPY_BUFFER_MAX 40
static
char
putcharSpyBuffer
[
SPY_BUFFER_MAX
];
#endif
...
...
@@ -3237,16 +3238,14 @@ void testNotEqualFloatArraysLengthZero(void)
TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \
}
void
testFloat
Verbose
Printing
(
void
)
void
testFloatPrinting
(
void
)
{
#if !defined(UNITY_EXCLUDE_FLOAT_PRINT) && defined(USING_OUTPUT_SPY)
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE
();
#else
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.0"
,
0
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.000000..."
,
0
.
0000004
99
f
);
float
smallest
=
0
.
0000005
f
;
*
(
int
*
)
&
smallest
+=
1
;
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.000001"
,
smallest
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.007812"
,
0
.
007
8125
f
);
/*not if ties round away from 0*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.976562"
,
0
.
9765625
f
);
/*not if ties round away from 0*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.000001"
,
0
.
00000050000005
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.100469"
,
0
.
100469499
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.0"
,
0
.
9999995
f
);
/*Rounding to int place*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.0"
,
1
.
0
f
);
...
...
@@ -3257,37 +3256,109 @@ void testFloatVerbosePrinting(void)
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"16.000006"
,
16
.
000006
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4294967040.0"
,
4294967040
.
0
f
);
/*Last full print integer*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.0"
,
-
0
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-0.000000..."
,
-
0
.
0000004
99
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-0.000001"
,
-
0
.
00000050000005
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-0.100469"
,
-
0
.
100469499
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-1.0"
,
-
0
.
9999995
f
);
/*Rounding to int place*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-1.0"
,
-
1
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-1.25"
,
-
1
.
25
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-7.999999"
,
-
7
.
999999
f
);
/*Not rounding*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-16.000002"
,
-
16
.
000002
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-16.000004"
,
-
16
.
000004
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-16.000006"
,
-
16
.
000006
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-4294967040.0"
,
-
4294967040
.
0
f
);
/*Last full print integer*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4.2949673e+09"
,
4294967296
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"5.0e+09"
,
5000000000
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"8.0e+09"
,
8.0e+09
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"8.3099991e+09"
,
8309999104
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.0e+10"
,
1.0e+10
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.0e+10"
,
10000000000
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.00005499e+10"
,
1.000055e+10
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.10000006e+38"
,
1.10000005e+38
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.63529943e+10"
,
1.63529943e+10
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"3.40282347e+38"
,
3.40282346638e38
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-1.0e+10"
,
-
1.0e+10
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-3.40282347e+38"
,
-
3.40282346638e38
f
);
#endif
}
void
testFloatPrintingRoundTiesToEven
(
void
)
{
#if defined(UNITY_EXCLUDE_FLOAT) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE
();
#else
#ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.007813"
,
0
.
007
8125
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.976563"
,
0
.
9765625
f
);
#else
/* Default to Round ties to even */
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.007182"
,
0
.
0071
825
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.976562"
,
0
.
9765625
f
);
#endif
#endif
}
void
testFloatPrintingInfinityAndNaN
(
void
)
{
#if defined(UNITY_EXCLUDE_FLOAT) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE
();
#else
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"Inf"
,
3.40282346638e38
f
*
2
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"Inf"
,
1
.
0
f
/
f_zero
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-Inf"
,
-
3.40282346638e38
f
*
2
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"NaN"
,
-
3.40282346638e38
f
*
2
.
0
f
*
f_zero
);
#endif
}
//Double
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
(
"1.0e+10"
,
10000000050
.
0
);
/*not if ties round away from 0*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9.00719924e+15"
,
9007199245000000
.
0
);
/*not if ties round away from 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
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录