Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
ed9c205b
Commit
ed9c205b
authored
May 15, 2020
by
chenguoping
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add somes test cases
parent
5dd27f1a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
test/src/unit-cbor.cpp
test/src/unit-cbor.cpp
+59
-0
No files found.
test/src/unit-cbor.cpp
View file @
ed9c205b
...
@@ -923,6 +923,65 @@ TEST_CASE("CBOR")
...
@@ -923,6 +923,65 @@ TEST_CASE("CBOR")
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
CHECK
(
json
::
from_cbor
(
result
)
==
v
);
CHECK
(
json
::
from_cbor
(
result
)
==
v
);
}
}
SECTION
(
"3.40282e+38(max float)"
)
{
float
v
=
std
::
numeric_limits
<
float
>::
max
();
json
j
=
v
;
std
::
vector
<
uint8_t
>
expected
=
{
0xfa
,
0x7f
,
0x7f
,
0xff
,
0xff
};
const
auto
result
=
json
::
to_cbor
(
j
);
CHECK
(
result
==
expected
);
// roundtrip
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
CHECK
(
json
::
from_cbor
(
result
)
==
v
);
}
SECTION
(
"-3.40282e+38(lowest float)"
)
{
double
v
=
std
::
numeric_limits
<
float
>::
lowest
();
json
j
=
v
;
std
::
vector
<
uint8_t
>
expected
=
{
0xfa
,
0xff
,
0x7f
,
0xff
,
0xff
};
const
auto
result
=
json
::
to_cbor
(
j
);
CHECK
(
result
==
expected
);
// roundtrip
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
CHECK
(
json
::
from_cbor
(
result
)
==
v
);
}
SECTION
(
"1 + 3.40282e+38(more than max float)"
)
{
double
v
=
std
::
numeric_limits
<
float
>::
max
()
+
0.1e+34
;
json
j
=
v
;
std
::
vector
<
uint8_t
>
expected
=
{
0xfb
,
0x47
,
0xf0
,
0x00
,
0x03
,
0x04
,
0xdc
,
0x64
,
0x49
};
// double
const
auto
result
=
json
::
to_cbor
(
j
);
CHECK
(
result
==
expected
);
// roundtrip
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
CHECK
(
json
::
from_cbor
(
result
)
==
v
);
}
SECTION
(
"-1 - 3.40282e+38(less than lowest float)"
)
{
double
v
=
std
::
numeric_limits
<
float
>::
lowest
()
-
1
;
json
j
=
v
;
std
::
vector
<
uint8_t
>
expected
=
{
0xfa
,
0xff
,
0x7f
,
0xff
,
0xff
};
// the same with lowest float
const
auto
result
=
json
::
to_cbor
(
j
);
CHECK
(
result
==
expected
);
// roundtrip
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
CHECK
(
json
::
from_cbor
(
result
)
==
v
);
}
}
}
SECTION
(
"half-precision float (edge cases)"
)
SECTION
(
"half-precision float (edge cases)"
)
...
...
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