mirror of
https://github.com/USCiLab/cereal.git
synced 2025-10-18 01:45:52 +02:00
Switching to CMake and splitting unittests
This commit is contained in:
committed by
Shane Grant
parent
94cb6d3ba8
commit
ba2ca7c94d
106
unittests/unordered_set.cpp
Normal file
106
unittests/unordered_set.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "common.hpp"
|
||||
|
||||
template <class IArchive, class OArchive>
|
||||
void test_unordered_set()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
std::unordered_set<int> o_podunordered_set;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_podunordered_set.insert(random_value<int>(gen));
|
||||
|
||||
std::unordered_set<StructInternalSerialize, StructHash<StructInternalSerialize>> o_iserunordered_set;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_iserunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
|
||||
|
||||
std::unordered_set<StructInternalSplit, StructHash<StructInternalSplit>> o_isplunordered_set;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_isplunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
|
||||
|
||||
std::unordered_set<StructExternalSerialize, StructHash<StructExternalSerialize>> o_eserunordered_set;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_eserunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
|
||||
|
||||
std::unordered_set<StructExternalSplit, StructHash<StructExternalSplit>> o_esplunordered_set;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_esplunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_podunordered_set);
|
||||
oar(o_iserunordered_set);
|
||||
oar(o_isplunordered_set);
|
||||
oar(o_eserunordered_set);
|
||||
oar(o_esplunordered_set);
|
||||
}
|
||||
|
||||
std::unordered_set<int> i_podunordered_set;
|
||||
std::unordered_set<StructInternalSerialize, StructHash<StructInternalSerialize>> i_iserunordered_set;
|
||||
std::unordered_set<StructInternalSplit, StructHash<StructInternalSplit>> i_isplunordered_set;
|
||||
std::unordered_set<StructExternalSerialize, StructHash<StructExternalSerialize>> i_eserunordered_set;
|
||||
std::unordered_set<StructExternalSplit, StructHash<StructExternalSplit>> i_esplunordered_set;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar(i_podunordered_set);
|
||||
iar(i_iserunordered_set);
|
||||
iar(i_isplunordered_set);
|
||||
iar(i_eserunordered_set);
|
||||
iar(i_esplunordered_set);
|
||||
}
|
||||
|
||||
for(auto const & p : i_podunordered_set)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(o_podunordered_set.count(p), 1);
|
||||
}
|
||||
|
||||
for(auto const & p : i_iserunordered_set)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(o_iserunordered_set.count(p), 1);
|
||||
}
|
||||
|
||||
for(auto const & p : i_isplunordered_set)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(o_isplunordered_set.count(p), 1);
|
||||
}
|
||||
|
||||
for(auto const & p : i_eserunordered_set)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(o_eserunordered_set.count(p), 1);
|
||||
}
|
||||
|
||||
for(auto const & p : i_esplunordered_set)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(o_esplunordered_set.count(p), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( binary_unordered_set )
|
||||
{
|
||||
test_unordered_set<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( portable_binary_unordered_set )
|
||||
{
|
||||
test_unordered_set<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( xml_unordered_set )
|
||||
{
|
||||
test_unordered_set<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( json_unordered_set )
|
||||
{
|
||||
test_unordered_set<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user