This source file includes following definitions.
- BOOST_AUTO_TEST_SUITE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include "stdafx.h"
22
23 #define BOOST_TEST_MODULE libjmmcg_tests
24 #include <boost/test/included/unit_test.hpp>
25
26 #include "core/unordered_tuple.hpp"
27
28 struct base {
29 using key_type=std::int32_t;
30
31 struct hasher {
32 constexpr key_type operator()(key_type k) const noexcept(true) {
33 return k;
34 }
35 constexpr key_type operator()(key_type k, std::size_t) const noexcept(true) {
36 return k;
37 }
38 };
39
40 virtual ~base()=default;
41
42 virtual int fn(int j) const=0;
43 };
44 struct derived1 final : base {
45 static constexpr base::key_type hash=1;
46
47 const int i_;
48
49 explicit derived1(int i)
50 : i_(i) {}
51
52 int fn(int j) const override {
53 return i_*j;
54 }
55 };
56 constexpr base::key_type derived1::hash;
57 struct derived2 final : base {
58 static constexpr base::key_type hash=2;
59
60 const int i_;
61
62 explicit derived2(int i)
63 : i_(i) {}
64
65 int fn(int j) const override {
66 return i_+j;
67 }
68 };
69 constexpr base::key_type derived2::hash;
70
71 template<class T>
72 struct extract {
73 static constexpr const typename T::key_type value=T::hash;
74 };
75
76 BOOST_AUTO_TEST_SUITE(unordered_tuple_tests)
77
78 BOOST_AUTO_TEST_CASE(unordered_tuple) {
79 using collection_type=jmmcg::unordered_tuple<base::key_type, base, base::hasher, extract, derived1, derived2>;
80
81 collection_type colln(derived1(667), derived2(42));
82 BOOST_CHECK_EQUAL(colln[derived1::hash].fn(1), 667);
83 BOOST_CHECK_EQUAL(colln[derived2::hash].fn(13), 55);
84 }
85
86 BOOST_AUTO_TEST_SUITE_END()