21 #define BOOST_TEST_MODULE libjmmcg_tests
22 #include <boost/test/included/unit_test.hpp>
24 #include "core/unordered_tuple.hpp"
26 using namespace libjmmcg;
29 using key_type=
std::int32_t;
32 constexpr key_type
operator()(key_type k)
const noexcept(
true) {
35 constexpr key_type
operator()(key_type k,
std::size_t)
const noexcept(
true) {
40 virtual int fn(
int j)
const=0;
53 int fn(
int j)
const override {
65 int fn(
int j)
const override {
69 struct double1
final :
base {
77 int fn(
int j)
const override {
78 return static_cast<
int>(
i_+j);
87 BOOST_AUTO_TEST_SUITE(unordered_tuple_tests)
89 BOOST_AUTO_TEST_CASE(ctor) {
90 using collection_type=unordered_tuple<base::key_type, base, base::hasher, extract, int1, int2, double1>;
92 BOOST_CHECK_NO_THROW(collection_type colln(int1(667), int2(42), double1(68.999999)));
95 BOOST_AUTO_TEST_CASE(access_in_order) {
96 using collection_type=unordered_tuple<base::key_type, base, base::hasher, extract, int1, int2, double1>;
98 collection_type colln(int1(667), int2(42), double1(68.999999));
99 BOOST_CHECK_EQUAL(colln[int1::hash].fn(1), 667);
100 BOOST_CHECK_EQUAL(colln[int2::hash].fn(13), 55);
101 BOOST_CHECK_EQUAL(colln[double1::hash].fn(7), 75);
104 BOOST_AUTO_TEST_CASE(access_reverse_order) {
105 using collection_type=unordered_tuple<base::key_type, base, base::hasher, extract, int1, int2, double1>;
107 collection_type colln(int1(667), int2(42), double1(68.999999));
108 BOOST_CHECK_EQUAL(colln[double1::hash].fn(7), 75);
109 BOOST_CHECK_EQUAL(colln[int2::hash].fn(13), 55);
110 BOOST_CHECK_EQUAL(colln[int1::hash].fn(1), 667);
113 BOOST_AUTO_TEST_CASE(access_in_then_reverse_order) {
114 using collection_type=unordered_tuple<base::key_type, base, base::hasher, extract, int1, int2, double1>;
116 collection_type colln(int1(667), int2(42), double1(68.999999));
117 BOOST_CHECK_EQUAL(colln[int1::hash].fn(1), 667);
118 BOOST_CHECK_EQUAL(colln[int2::hash].fn(13), 55);
119 BOOST_CHECK_EQUAL(colln[double1::hash].fn(7), 75);
120 BOOST_CHECK_EQUAL(colln[double1::hash].fn(7), 75);
121 BOOST_CHECK_EQUAL(colln[int2::hash].fn(13), 55);
122 BOOST_CHECK_EQUAL(colln[int1::hash].fn(1), 667);
125 BOOST_AUTO_TEST_CASE(access_reverse_then_in_order) {
126 using collection_type=unordered_tuple<base::key_type, base, base::hasher, extract, int1, int2, double1>;
128 collection_type colln(int1(667), int2(42), double1(68.999999));
129 BOOST_CHECK_EQUAL(colln[double1::hash].fn(7), 75);
130 BOOST_CHECK_EQUAL(colln[int2::hash].fn(13), 55);
131 BOOST_CHECK_EQUAL(colln[int1::hash].fn(1), 667);
132 BOOST_CHECK_EQUAL(colln[int1::hash].fn(1), 667);
133 BOOST_CHECK_EQUAL(colln[int2::hash].fn(13), 55);
134 BOOST_CHECK_EQUAL(colln[double1::hash].fn(7), 75);
137 BOOST_AUTO_TEST_SUITE_END()