2 Copyright (c) 2014, Randolph Voorhies, Shane Grant
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of cereal nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <boost/test/unit_test.hpp>
30 template <class IArchive, class OArchive>
31 void test_unordered_set()
33 std::random_device rd;
34 std::mt19937 gen(rd());
36 for(int ii=0; ii<100; ++ii)
38 std::unordered_set<int> o_podunordered_set;
39 for(int j=0; j<100; ++j)
40 o_podunordered_set.insert(random_value<int>(gen));
42 std::unordered_set<StructInternalSerialize, StructHash<StructInternalSerialize>> o_iserunordered_set;
43 for(int j=0; j<100; ++j)
44 o_iserunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
46 std::unordered_set<StructInternalSplit, StructHash<StructInternalSplit>> o_isplunordered_set;
47 for(int j=0; j<100; ++j)
48 o_isplunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
50 std::unordered_set<StructExternalSerialize, StructHash<StructExternalSerialize>> o_eserunordered_set;
51 for(int j=0; j<100; ++j)
52 o_eserunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
54 std::unordered_set<StructExternalSplit, StructHash<StructExternalSplit>> o_esplunordered_set;
55 for(int j=0; j<100; ++j)
56 o_esplunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
58 std::ostringstream os;
62 oar(o_podunordered_set);
63 oar(o_iserunordered_set);
64 oar(o_isplunordered_set);
65 oar(o_eserunordered_set);
66 oar(o_esplunordered_set);
69 std::unordered_set<int> i_podunordered_set;
70 std::unordered_set<StructInternalSerialize, StructHash<StructInternalSerialize>> i_iserunordered_set;
71 std::unordered_set<StructInternalSplit, StructHash<StructInternalSplit>> i_isplunordered_set;
72 std::unordered_set<StructExternalSerialize, StructHash<StructExternalSerialize>> i_eserunordered_set;
73 std::unordered_set<StructExternalSplit, StructHash<StructExternalSplit>> i_esplunordered_set;
75 std::istringstream is(os.str());
79 iar(i_podunordered_set);
80 iar(i_iserunordered_set);
81 iar(i_isplunordered_set);
82 iar(i_eserunordered_set);
83 iar(i_esplunordered_set);
86 for(auto const & p : i_podunordered_set)
88 BOOST_CHECK_EQUAL(o_podunordered_set.count(p), 1);
91 for(auto const & p : i_iserunordered_set)
93 BOOST_CHECK_EQUAL(o_iserunordered_set.count(p), 1);
96 for(auto const & p : i_isplunordered_set)
98 BOOST_CHECK_EQUAL(o_isplunordered_set.count(p), 1);
101 for(auto const & p : i_eserunordered_set)
103 BOOST_CHECK_EQUAL(o_eserunordered_set.count(p), 1);
106 for(auto const & p : i_esplunordered_set)
108 BOOST_CHECK_EQUAL(o_esplunordered_set.count(p), 1);
113 BOOST_AUTO_TEST_CASE( binary_unordered_set )
115 test_unordered_set<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
118 BOOST_AUTO_TEST_CASE( portable_binary_unordered_set )
120 test_unordered_set<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
123 BOOST_AUTO_TEST_CASE( xml_unordered_set )
125 test_unordered_set<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
128 BOOST_AUTO_TEST_CASE( json_unordered_set )
130 test_unordered_set<cereal::JSONInputArchive, cereal::JSONOutputArchive>();