diff --git a/unittests.cpp b/unittests.cpp index 7f740495..f390d9be 100644 --- a/unittests.cpp +++ b/unittests.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -50,7 +51,6 @@ std::ostream& operator<<(std::ostream& os, StructBase const & s) return os; } - struct StructInternalSerialize : StructBase { StructInternalSerialize() : StructBase{0,0} {} @@ -109,6 +109,19 @@ void load(Archive & ar, StructExternalSplit & s) ar & s.x & s.y; } + +template +struct StructHash { + public: + size_t operator()(const T & s) const + { + size_t h1 = std::hash()(s.x); + size_t h2 = std::hash()(s.y); + return h1 ^ ( h2 << 1 ); + } +}; + + template typename std::enable_if::value, T>::type random_value(std::mt19937 & gen) @@ -1186,3 +1199,82 @@ BOOST_AUTO_TEST_CASE( binary_unordered_multimap ) } } } + +// ###################################################################### +BOOST_AUTO_TEST_CASE( binary_unordered_set ) +{ + std::random_device rd; + std::mt19937 gen(rd()); + + for(int i=0; i<100; ++i) + { + std::ostringstream os; + cereal::BinaryOutputArchive oar(os); + + std::unordered_set o_podunordered_set; + for(int j=0; j<100; ++j) + o_podunordered_set.insert(random_value(gen)); + + std::unordered_set> o_iserunordered_set; + for(int j=0; j<100; ++j) + o_iserunordered_set.insert({ random_value(gen), random_value(gen) }); + + std::unordered_set> o_isplunordered_set; + for(int j=0; j<100; ++j) + o_isplunordered_set.insert({ random_value(gen), random_value(gen) }); + + std::unordered_set> o_eserunordered_set; + for(int j=0; j<100; ++j) + o_eserunordered_set.insert({ random_value(gen), random_value(gen) }); + + std::unordered_set> o_esplunordered_set; + for(int j=0; j<100; ++j) + o_esplunordered_set.insert({ random_value(gen), random_value(gen) }); + + oar & o_podunordered_set; + oar & o_iserunordered_set; + oar & o_isplunordered_set; + oar & o_eserunordered_set; + oar & o_esplunordered_set; + + std::istringstream is(os.str()); + cereal::BinaryInputArchive iar(is); + + std::unordered_set i_podunordered_set; + std::unordered_set> i_iserunordered_set; + std::unordered_set> i_isplunordered_set; + std::unordered_set> i_eserunordered_set; + std::unordered_set> i_esplunordered_set; + + 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); + } + } +}