Skip to content

Commit b5e500d

Browse files
committed
1 parent a6e59d7 commit b5e500d

File tree

4 files changed

+230
-162
lines changed

4 files changed

+230
-162
lines changed

unittests/priority_queue.cpp

Lines changed: 8 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -24,102 +24,29 @@
2424
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2525
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*/
27-
#include "common.hpp"
28-
#include <boost/test/unit_test.hpp>
27+
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
28+
#include "priority_queue.hpp"
2929

30-
template <class IArchive, class OArchive>
31-
void test_priority_queue()
32-
{
33-
std::random_device rd;
34-
std::mt19937 gen(rd());
35-
36-
for(int ii=0; ii<100; ++ii)
37-
{
38-
std::priority_queue<int> o_podpriority_queue;
39-
for(int j=0; j<100; ++j)
40-
o_podpriority_queue.push(random_value<int>(gen));
41-
42-
std::priority_queue<StructInternalSerialize> o_iserpriority_queue;
43-
for(int j=0; j<100; ++j)
44-
o_iserpriority_queue.push({ random_value<int>(gen), random_value<int>(gen) });
45-
46-
std::priority_queue<StructInternalSplit> o_isplpriority_queue;
47-
for(int j=0; j<100; ++j)
48-
o_isplpriority_queue.push({ random_value<int>(gen), random_value<int>(gen) });
49-
50-
std::priority_queue<StructExternalSerialize> o_eserpriority_queue;
51-
for(int j=0; j<100; ++j)
52-
o_eserpriority_queue.push({ random_value<int>(gen), random_value<int>(gen) });
53-
54-
std::priority_queue<StructExternalSplit> o_esplpriority_queue;
55-
for(int j=0; j<100; ++j)
56-
o_esplpriority_queue.push({ random_value<int>(gen), random_value<int>(gen) });
57-
58-
std::ostringstream os;
59-
{
60-
OArchive oar(os);
61-
62-
oar(o_podpriority_queue);
63-
oar(o_iserpriority_queue);
64-
oar(o_isplpriority_queue);
65-
oar(o_eserpriority_queue);
66-
oar(o_esplpriority_queue);
67-
}
68-
69-
std::priority_queue<int> i_podpriority_queue;
70-
std::priority_queue<StructInternalSerialize> i_iserpriority_queue;
71-
std::priority_queue<StructInternalSplit> i_isplpriority_queue;
72-
std::priority_queue<StructExternalSerialize> i_eserpriority_queue;
73-
std::priority_queue<StructExternalSplit> i_esplpriority_queue;
74-
75-
std::istringstream is(os.str());
76-
{
77-
IArchive iar(is);
78-
79-
iar(i_podpriority_queue);
80-
iar(i_iserpriority_queue);
81-
iar(i_isplpriority_queue);
82-
iar(i_eserpriority_queue);
83-
iar(i_esplpriority_queue);
84-
}
85-
86-
auto & i_podpriority_queue_c = cereal::queue_detail::container(i_podpriority_queue);
87-
auto & i_iserpriority_queue_c = cereal::queue_detail::container(i_iserpriority_queue);
88-
auto & i_isplpriority_queue_c = cereal::queue_detail::container(i_isplpriority_queue);
89-
auto & i_eserpriority_queue_c = cereal::queue_detail::container(i_eserpriority_queue);
90-
auto & i_esplpriority_queue_c = cereal::queue_detail::container(i_esplpriority_queue);
91-
92-
auto & o_podpriority_queue_c = cereal::queue_detail::container(o_podpriority_queue);
93-
auto & o_iserpriority_queue_c = cereal::queue_detail::container(o_iserpriority_queue);
94-
auto & o_isplpriority_queue_c = cereal::queue_detail::container(o_isplpriority_queue);
95-
auto & o_eserpriority_queue_c = cereal::queue_detail::container(o_eserpriority_queue);
96-
auto & o_esplpriority_queue_c = cereal::queue_detail::container(o_esplpriority_queue);
97-
98-
BOOST_CHECK_EQUAL_COLLECTIONS(i_podpriority_queue_c.begin(), i_podpriority_queue_c.end(), o_podpriority_queue_c.begin(), o_podpriority_queue_c.end());
99-
BOOST_CHECK_EQUAL_COLLECTIONS(i_iserpriority_queue_c.begin(), i_iserpriority_queue_c.end(), o_iserpriority_queue_c.begin(), o_iserpriority_queue_c.end());
100-
BOOST_CHECK_EQUAL_COLLECTIONS(i_isplpriority_queue_c.begin(), i_isplpriority_queue_c.end(), o_isplpriority_queue_c.begin(), o_isplpriority_queue_c.end());
101-
BOOST_CHECK_EQUAL_COLLECTIONS(i_eserpriority_queue_c.begin(), i_eserpriority_queue_c.end(), o_eserpriority_queue_c.begin(), o_eserpriority_queue_c.end());
102-
BOOST_CHECK_EQUAL_COLLECTIONS(i_esplpriority_queue_c.begin(), i_esplpriority_queue_c.end(), o_esplpriority_queue_c.begin(), o_esplpriority_queue_c.end());
103-
}
104-
}
30+
TEST_SUITE("priority_queue");
10531

106-
BOOST_AUTO_TEST_CASE( binary_priority_queue )
32+
TEST_CASE("binary_priority_queue")
10733
{
10834
test_priority_queue<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
10935
}
11036

111-
BOOST_AUTO_TEST_CASE( portable_binary_priority_queue )
37+
TEST_CASE("portable_binary_priority_queue")
11238
{
11339
test_priority_queue<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
11440
}
11541

116-
BOOST_AUTO_TEST_CASE( xml_priority_queue )
42+
TEST_CASE("xml_priority_queue")
11743
{
11844
test_priority_queue<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
11945
}
12046

121-
BOOST_AUTO_TEST_CASE( json_priority_queue )
47+
TEST_CASE("json_priority_queue")
12248
{
12349
test_priority_queue<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
12450
}
12551

52+
TEST_SUITE_END();

unittests/priority_queue.hpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
Copyright (c) 2014, Randolph Voorhies, Shane Grant
3+
All rights reserved.
4+
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.
15+
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.
26+
*/
27+
#ifndef CEREAL_TEST_PRIORITY_QUEUE_H_
28+
#define CEREAL_TEST_PRIORITY_QUEUE_H_
29+
#include "common.hpp"
30+
31+
template <class IArchive, class OArchive> inline
32+
void test_priority_queue()
33+
{
34+
std::random_device rd;
35+
std::mt19937 gen(rd());
36+
37+
for(int ii=0; ii<100; ++ii)
38+
{
39+
std::priority_queue<int> o_podpriority_queue;
40+
for(int j=0; j<100; ++j)
41+
o_podpriority_queue.push(random_value<int>(gen));
42+
43+
std::priority_queue<StructInternalSerialize> o_iserpriority_queue;
44+
for(int j=0; j<100; ++j)
45+
o_iserpriority_queue.push({ random_value<int>(gen), random_value<int>(gen) });
46+
47+
std::priority_queue<StructInternalSplit> o_isplpriority_queue;
48+
for(int j=0; j<100; ++j)
49+
o_isplpriority_queue.push({ random_value<int>(gen), random_value<int>(gen) });
50+
51+
std::priority_queue<StructExternalSerialize> o_eserpriority_queue;
52+
for(int j=0; j<100; ++j)
53+
o_eserpriority_queue.push({ random_value<int>(gen), random_value<int>(gen) });
54+
55+
std::priority_queue<StructExternalSplit> o_esplpriority_queue;
56+
for(int j=0; j<100; ++j)
57+
o_esplpriority_queue.push({ random_value<int>(gen), random_value<int>(gen) });
58+
59+
std::ostringstream os;
60+
{
61+
OArchive oar(os);
62+
63+
oar(o_podpriority_queue);
64+
oar(o_iserpriority_queue);
65+
oar(o_isplpriority_queue);
66+
oar(o_eserpriority_queue);
67+
oar(o_esplpriority_queue);
68+
}
69+
70+
std::priority_queue<int> i_podpriority_queue;
71+
std::priority_queue<StructInternalSerialize> i_iserpriority_queue;
72+
std::priority_queue<StructInternalSplit> i_isplpriority_queue;
73+
std::priority_queue<StructExternalSerialize> i_eserpriority_queue;
74+
std::priority_queue<StructExternalSplit> i_esplpriority_queue;
75+
76+
std::istringstream is(os.str());
77+
{
78+
IArchive iar(is);
79+
80+
iar(i_podpriority_queue);
81+
iar(i_iserpriority_queue);
82+
iar(i_isplpriority_queue);
83+
iar(i_eserpriority_queue);
84+
iar(i_esplpriority_queue);
85+
}
86+
87+
auto & i_podpriority_queue_c = cereal::queue_detail::container(i_podpriority_queue);
88+
auto & i_iserpriority_queue_c = cereal::queue_detail::container(i_iserpriority_queue);
89+
auto & i_isplpriority_queue_c = cereal::queue_detail::container(i_isplpriority_queue);
90+
auto & i_eserpriority_queue_c = cereal::queue_detail::container(i_eserpriority_queue);
91+
auto & i_esplpriority_queue_c = cereal::queue_detail::container(i_esplpriority_queue);
92+
93+
auto & o_podpriority_queue_c = cereal::queue_detail::container(o_podpriority_queue);
94+
auto & o_iserpriority_queue_c = cereal::queue_detail::container(o_iserpriority_queue);
95+
auto & o_isplpriority_queue_c = cereal::queue_detail::container(o_isplpriority_queue);
96+
auto & o_eserpriority_queue_c = cereal::queue_detail::container(o_eserpriority_queue);
97+
auto & o_esplpriority_queue_c = cereal::queue_detail::container(o_esplpriority_queue);
98+
99+
check_collection(i_podpriority_queue_c, o_podpriority_queue_c);
100+
check_collection(i_iserpriority_queue_c, o_iserpriority_queue_c);
101+
check_collection(i_isplpriority_queue_c, o_isplpriority_queue_c);
102+
check_collection(i_eserpriority_queue_c, o_eserpriority_queue_c);
103+
check_collection(i_esplpriority_queue_c, o_esplpriority_queue_c);
104+
}
105+
}
106+
107+
#endif // CEREAL_TEST_PRIORITY_QUEUE_H_

unittests/queue.cpp

Lines changed: 8 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -24,102 +24,29 @@
2424
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2525
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*/
27-
#include "common.hpp"
28-
#include <boost/test/unit_test.hpp>
27+
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
28+
#include "queue.hpp"
2929

30-
template <class IArchive, class OArchive>
31-
void test_queue()
32-
{
33-
std::random_device rd;
34-
std::mt19937 gen(rd());
35-
36-
for(int ii=0; ii<100; ++ii)
37-
{
38-
std::queue<int> o_podqueue;
39-
for(int j=0; j<100; ++j)
40-
o_podqueue.push(random_value<int>(gen));
41-
42-
std::queue<StructInternalSerialize> o_iserqueue;
43-
for(int j=0; j<100; ++j)
44-
o_iserqueue.push({ random_value<int>(gen), random_value<int>(gen) });
45-
46-
std::queue<StructInternalSplit> o_isplqueue;
47-
for(int j=0; j<100; ++j)
48-
o_isplqueue.push({ random_value<int>(gen), random_value<int>(gen) });
49-
50-
std::queue<StructExternalSerialize> o_eserqueue;
51-
for(int j=0; j<100; ++j)
52-
o_eserqueue.push({ random_value<int>(gen), random_value<int>(gen) });
53-
54-
std::queue<StructExternalSplit> o_esplqueue;
55-
for(int j=0; j<100; ++j)
56-
o_esplqueue.push({ random_value<int>(gen), random_value<int>(gen) });
57-
58-
std::ostringstream os;
59-
{
60-
OArchive oar(os);
61-
62-
oar(o_podqueue);
63-
oar(o_iserqueue);
64-
oar(o_isplqueue);
65-
oar(o_eserqueue);
66-
oar(o_esplqueue);
67-
}
68-
69-
std::queue<int> i_podqueue;
70-
std::queue<StructInternalSerialize> i_iserqueue;
71-
std::queue<StructInternalSplit> i_isplqueue;
72-
std::queue<StructExternalSerialize> i_eserqueue;
73-
std::queue<StructExternalSplit> i_esplqueue;
74-
75-
std::istringstream is(os.str());
76-
{
77-
IArchive iar(is);
78-
79-
iar(i_podqueue);
80-
iar(i_iserqueue);
81-
iar(i_isplqueue);
82-
iar(i_eserqueue);
83-
iar(i_esplqueue);
84-
}
85-
86-
auto & i_podqueue_c = cereal::queue_detail::container(i_podqueue);
87-
auto & i_iserqueue_c = cereal::queue_detail::container(i_iserqueue);
88-
auto & i_isplqueue_c = cereal::queue_detail::container(i_isplqueue);
89-
auto & i_eserqueue_c = cereal::queue_detail::container(i_eserqueue);
90-
auto & i_esplqueue_c = cereal::queue_detail::container(i_esplqueue);
91-
92-
auto & o_podqueue_c = cereal::queue_detail::container(o_podqueue);
93-
auto & o_iserqueue_c = cereal::queue_detail::container(o_iserqueue);
94-
auto & o_isplqueue_c = cereal::queue_detail::container(o_isplqueue);
95-
auto & o_eserqueue_c = cereal::queue_detail::container(o_eserqueue);
96-
auto & o_esplqueue_c = cereal::queue_detail::container(o_esplqueue);
97-
98-
BOOST_CHECK_EQUAL_COLLECTIONS(i_podqueue_c.begin(), i_podqueue_c.end(), o_podqueue_c.begin(), o_podqueue_c.end());
99-
BOOST_CHECK_EQUAL_COLLECTIONS(i_iserqueue_c.begin(), i_iserqueue_c.end(), o_iserqueue_c.begin(), o_iserqueue_c.end());
100-
BOOST_CHECK_EQUAL_COLLECTIONS(i_isplqueue_c.begin(), i_isplqueue_c.end(), o_isplqueue_c.begin(), o_isplqueue_c.end());
101-
BOOST_CHECK_EQUAL_COLLECTIONS(i_eserqueue_c.begin(), i_eserqueue_c.end(), o_eserqueue_c.begin(), o_eserqueue_c.end());
102-
BOOST_CHECK_EQUAL_COLLECTIONS(i_esplqueue_c.begin(), i_esplqueue_c.end(), o_esplqueue_c.begin(), o_esplqueue_c.end());
103-
}
104-
}
30+
TEST_SUITE("queue");
10531

106-
BOOST_AUTO_TEST_CASE( binary_queue )
32+
TEST_CASE("binary_queue")
10733
{
10834
test_queue<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
10935
}
11036

111-
BOOST_AUTO_TEST_CASE( portable_binary_queue )
37+
TEST_CASE("portable_binary_queue")
11238
{
11339
test_queue<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
11440
}
11541

116-
BOOST_AUTO_TEST_CASE( xml_queue )
42+
TEST_CASE("xml_queue")
11743
{
11844
test_queue<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
11945
}
12046

121-
BOOST_AUTO_TEST_CASE( json_queue )
47+
TEST_CASE("json_queue")
12248
{
12349
test_queue<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
12450
}
12551

52+
TEST_SUITE_END();

0 commit comments

Comments
 (0)