Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
c69ff41f
Commit
c69ff41f
authored
Apr 15, 2015
by
miloyip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for parsing number with exhaustive exponents and random signifcant
parent
76d67b7e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
16 deletions
+28
-16
readertest.cpp
test/unittest/readertest.cpp
+28
-16
No files found.
test/unittest/readertest.cpp
View file @
c69ff41f
...
...
@@ -302,28 +302,40 @@ static void TestParseDouble() {
"e-308"
,
2.2250738585072014e-308
);
#if 0 // Very slow
static const unsigned count = 10000000;
// Random test for double
{
static
const
unsigned
count
=
1000
;
// Tested with 1000000 locally
Random
r
;
Reader
reader
;
// Reusing reader to prevent heap allocation
for (unsigned i = 0; i < count; i++) {
internal::Double d;
do {
// Exhaustively test different exponents with random significant
for
(
uint64_t
exp
=
0
;
exp
<
2047
;
exp
++
)
{
;
for
(
unsigned
i
=
0
;
i
<
count
;
i
++
)
{
// Need to call r() in two statements for cross-platform coherent sequence.
uint64_t u =
uint64_t(r()
) << 32;
uint64_t
u
=
(
exp
<<
52
)
|
uint64_t
(
r
()
&
0x000FFFFF
)
<<
32
;
u
|=
uint64_t
(
r
());
d = internal::Double(u);
} while (d.IsNan() || d.IsInf()/* || !d.IsNormal()*/); // Also work for subnormal now
char buffer[32];
*internal::dtoa(d.Value(), buffer) = '\0';
TEST_DOUBLE(fullPrecision, buffer, d.Value());
internal
::
Double
d
=
internal
::
Double
(
u
);
char
buffer
[
32
];
*
internal
::
dtoa
(
d
.
Value
(),
buffer
)
=
'\0'
;
StringStream
s
(
buffer
);
ParseDoubleHandler
h
;
ASSERT_EQ
(
kParseErrorNone
,
reader
.
Parse
<
fullPrecision
?
kParseFullPrecisionFlag
:
0
>
(
s
,
h
).
Code
());
EXPECT_EQ
(
1u
,
h
.
step_
);
internal
::
Double
a
(
h
.
actual_
);
if
(
fullPrecision
)
{
EXPECT_EQ
(
d
.
Uint64Value
(),
a
.
Uint64Value
());
if
(
d
.
Uint64Value
()
!=
a
.
Uint64Value
())
printf
(
" String: %sn Actual: %.17gnExpected: %.17gn"
,
buffer
,
h
.
actual_
,
d
.
Value
());
}
else
{
EXPECT_EQ
(
d
.
Sign
(),
a
.
Sign
());
/* for 0.0 != -0.0 */
EXPECT_DOUBLE_EQ
(
d
.
Value
(),
h
.
actual_
);
}
}
}
}
#endif
#undef TEST_DOUBLE
}
...
...
@@ -651,7 +663,7 @@ TEST(Reader, ParseString_Error) {
TEST_STRINGENCODING_ERROR
(
UTF32
<>
,
UTF8
<>
,
unsigned
,
ARRAY
(
'['
,
'\"'
,
0x110000
,
'\"'
,
']'
,
'\0'
));
// Malform ASCII sequence
TEST_STRINGENCODING_ERROR
(
ASCII
<>
,
UTF8
<>
,
char
,
ARRAY
(
'['
,
'\"'
,
0x80
,
'\"'
,
']'
,
'\0'
));
TEST_STRINGENCODING_ERROR
(
ASCII
<>
,
UTF8
<>
,
char
,
ARRAY
(
'['
,
'\"'
,
char
(
0x80
)
,
'\"'
,
']'
,
'\0'
));
#undef ARRAY
#undef TEST_STRINGARRAY_ERROR
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment