Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
496ddd12
Unverified
Commit
496ddd12
authored
Jul 15, 2020
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
💚
make test deterministic
parent
9449dfcc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
53 deletions
+48
-53
unit-hash.cpp
test/src/unit-hash.cpp
+48
-53
No files found.
test/src/unit-hash.cpp
View file @
496ddd12
...
...
@@ -32,59 +32,53 @@ SOFTWARE.
#include <nlohmann/json.hpp>
using
json
=
nlohmann
::
json
;
#include <set>
TEST_CASE
(
"hash"
)
{
SECTION
(
"null"
)
{
CHECK
(
std
::
hash
<
json
>
{}(
json
(
nullptr
))
==
2654435769U
);
}
SECTION
(
"boolean"
)
{
CHECK
(
std
::
hash
<
json
>
{}(
json
(
true
))
==
2654436031U
);
CHECK
(
std
::
hash
<
json
>
{}(
json
(
false
))
==
2654436030U
);
}
SECTION
(
"string"
)
{
CHECK
(
std
::
hash
<
json
>
{}(
json
(
""
))
==
11160318156688833227U
);
CHECK
(
std
::
hash
<
json
>
{}(
json
(
"foo"
))
==
910203211069189493U
);
}
SECTION
(
"number"
)
{
CHECK
(
std
::
hash
<
json
>
{}(
json
(
int
(
0
)))
==
2654436095U
);
CHECK
(
std
::
hash
<
json
>
{}(
json
(
unsigned
(
0
)))
==
2654436156U
);
CHECK
(
std
::
hash
<
json
>
{}(
json
(
-
1
))
==
2654436092U
);
CHECK
(
std
::
hash
<
json
>
{}(
json
(
0.0
))
==
2654436221U
);
CHECK
(
std
::
hash
<
json
>
{}(
json
(
42.23
))
==
4631140164097181104U
);
}
SECTION
(
"array"
)
{
CHECK
(
std
::
hash
<
json
>
{}(
json
::
array
())
==
2654435899U
);
CHECK
(
std
::
hash
<
json
>
{}(
json
::
array
({
1
,
2
,
3
}))
==
717272658337467U
);
}
SECTION
(
"object"
)
{
CHECK
(
std
::
hash
<
json
>
{}(
json
::
object
())
==
2654435832U
);
CHECK
(
std
::
hash
<
json
>
{}(
json
::
object
({{
"foo"
,
"bar"
}}))
==
4042265434648078139U
);
}
SECTION
(
"binary"
)
{
CHECK
(
std
::
hash
<
json
>
{}(
json
::
binary
({}))
==
11093832941624U
);
CHECK
(
std
::
hash
<
json
>
{}(
json
::
binary
({},
0
))
==
11093832941691U
);
CHECK
(
std
::
hash
<
json
>
{}(
json
::
binary
({},
42
))
==
11093832941581U
);
CHECK
(
std
::
hash
<
json
>
{}(
json
::
binary
({
1
,
2
,
3
}))
==
3005324138949694928U
);
CHECK
(
std
::
hash
<
json
>
{}(
json
::
binary
({
1
,
2
,
3
},
0
))
==
3005324138988516582U
);
CHECK
(
std
::
hash
<
json
>
{}(
json
::
binary
({
1
,
2
,
3
},
42
))
==
3005324138986241627U
);
}
SECTION
(
"discarded"
)
{
CHECK
(
std
::
hash
<
json
>
{}(
json
(
json
::
value_t
::
discarded
))
==
2654436338U
);
}
// Collect hashes for different JSON values and make sure that they are distinct
// We cannot compare against fixed values, because the implementation of
// std::hash may differ between compilers.
std
::
set
<
std
::
size_t
>
hashes
;
// null
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
(
nullptr
)));
// boolean
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
(
true
)));
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
(
false
)));
// string
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
(
""
)));
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
(
"foo"
)));
// number
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
(
int
(
0
))));
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
(
unsigned
(
0
))));
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
(
-
1
)));
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
(
0.0
)));
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
(
42.23
)));
// array
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
::
array
()));
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
::
array
({
1
,
2
,
3
})));
// object
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
::
object
()));
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
::
object
({{
"foo"
,
"bar"
}})));
// binary
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
::
binary
({})));
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
::
binary
({},
0
)));
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
::
binary
({},
42
)));
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
::
binary
({
1
,
2
,
3
})));
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
::
binary
({
1
,
2
,
3
},
0
)));
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
::
binary
({
1
,
2
,
3
},
42
)));
// discarded
hashes
.
insert
(
std
::
hash
<
json
>
{}(
json
(
json
::
value_t
::
discarded
)));
CHECK
(
hashes
.
size
()
==
21
);
}
\ No newline at end of file
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