File indexing completed on 2025-08-06 08:11:34
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Utilities/detail/MPL/all_of.hpp"
0012 #include "Acts/Utilities/detail/MPL/any_of.hpp"
0013 #include "Acts/Utilities/detail/MPL/are_sorted.hpp"
0014 #include "Acts/Utilities/detail/MPL/are_within.hpp"
0015 #include "Acts/Utilities/detail/MPL/at_index.hpp"
0016 #include "Acts/Utilities/detail/MPL/has_duplicates.hpp"
0017 #include "Acts/Utilities/detail/MPL/type_collector.hpp"
0018
0019 #include <tuple>
0020 #include <type_traits>
0021
0022 #include <boost/hana.hpp>
0023 #include <boost/hana/core/to.hpp>
0024 #include <boost/hana/equal.hpp>
0025 #include <boost/hana/ext/std/tuple.hpp>
0026 #include <boost/hana/integral_constant.hpp>
0027 #include <boost/hana/set.hpp>
0028 #include <boost/hana/transform.hpp>
0029 #include <boost/hana/tuple.hpp>
0030 #include <boost/hana/type.hpp>
0031 #include <boost/hana/union.hpp>
0032
0033 namespace hana = boost::hana;
0034 namespace Acts {
0035 namespace detail {
0036 template <bool ascending, bool strict, typename T, T... values>
0037 struct are_sorted;
0038 template <typename T, T MIN, T MAX, T... values>
0039 struct are_within;
0040 template <typename T, std::size_t index, T... values>
0041 struct at_index;
0042 }
0043
0044 namespace Test {
0045
0046 BOOST_AUTO_TEST_CASE(all_of_test) {
0047 using detail::all_of_v;
0048
0049 static_assert(!all_of_v<true, true, false>,
0050 "all_of_v<true, true, false> failed");
0051 static_assert(!all_of_v<false, true, true, false>,
0052 "all_of_v<false, true, true, false> failed");
0053 static_assert(all_of_v<true, true, true>,
0054 "all_of_v<true, true, true> failed");
0055 static_assert(all_of_v<true>, "all_of_v<true> failed");
0056 static_assert(!all_of_v<false>, "all_of_v<false> failed");
0057 static_assert(all_of_v<>, "all_of_v<> failed");
0058 }
0059
0060 BOOST_AUTO_TEST_CASE(hana_set_union_test) {
0061
0062 constexpr auto first = hana::make_set(hana::type_c<float>, hana::type_c<int>,
0063 hana::type_c<char>, hana::type_c<bool>);
0064
0065 constexpr auto second = hana::make_set(hana::type_c<long>, hana::type_c<int>);
0066 constexpr auto found = hana::union_(first, second);
0067
0068
0069 constexpr auto expected =
0070 hana::make_set(hana::type_c<float>, hana::type_c<int>, hana::type_c<char>,
0071 hana::type_c<bool>, hana::type_c<long>);
0072
0073 static_assert(found == expected, "union of hana::sets failed");
0074 }
0075
0076 BOOST_AUTO_TEST_CASE(hana_set_to_tuple_test) {
0077 constexpr auto a_set = hana::make_set(hana::type_c<float>, hana::type_c<int>,
0078 hana::type_c<char>, hana::type_c<bool>);
0079 constexpr auto h_tuple =
0080 hana::make_tuple(hana::type_c<float>, hana::type_c<int>,
0081 hana::type_c<char>, hana::type_c<bool>);
0082
0083 static_assert(hana::to<hana::tuple_tag>(a_set) == h_tuple, "not equal");
0084
0085
0086
0087
0088
0089
0090 }
0091
0092 template <typename... args>
0093 struct variadic_struct {
0094 using tuple = std::tuple<args...>;
0095 };
0096
0097 BOOST_AUTO_TEST_CASE(unpack_boost_set_as_template_test) {
0098 constexpr auto hana_set = hana::make_set(
0099 hana::type_c<float>, hana::type_c<int>, hana::type_c<char>);
0100 using found =
0101 decltype(hana::unpack(hana_set, hana::template_<variadic_struct>))::type;
0102
0103 using expected = variadic_struct<float, int, char>;
0104
0105 static_assert(std::is_same<found, expected>::value,
0106 "using boost::mpl::set for variadic templates failed");
0107
0108 static_assert(
0109 std::is_same<expected::tuple, std::tuple<float, int, char>>::value,
0110 "not equal");
0111 }
0112
0113 namespace {
0114 struct traits1 {
0115 using result_type = int;
0116 using action_type = char;
0117 };
0118
0119 template <bool>
0120 struct traits2;
0121
0122 template <>
0123 struct traits2<false> {
0124 using result_type = bool;
0125 using action_type = float;
0126 };
0127
0128 template <>
0129 struct traits2<true> {
0130 using action_type = float;
0131 };
0132 }
0133
0134 template <typename... Args>
0135 struct tuple_helper {
0136 using tuple = std::tuple<Args...>;
0137 };
0138
0139 BOOST_AUTO_TEST_CASE(type_collector_test) {
0140
0141 static_assert(detail::has_result_type_v<traits1>, "Did not find result type");
0142 static_assert(detail::has_result_type_v<traits2<false>>,
0143 "Did not find result type");
0144 static_assert(!detail::has_result_type_v<traits2<true>>,
0145 "Did find result type");
0146
0147 static_assert(detail::has_action_type_v<traits1>, "Did not find action type");
0148 static_assert(detail::has_action_type_v<traits2<false>>,
0149 "Did not find action type");
0150 static_assert(detail::has_action_type_v<traits2<true>>,
0151 "Did not find action type");
0152
0153 constexpr auto found_results =
0154 detail::type_collector_t<detail::result_type_extractor, traits1,
0155 traits2<true>, traits2<false>>;
0156 constexpr auto expected_results =
0157 hana::make_set(hana::type_c<int>, hana::type_c<bool>);
0158 static_assert(found_results == expected_results,
0159 "Didn't find expected results");
0160
0161
0162 using found_results_tuple = decltype(hana::unpack(
0163 found_results, hana::template_<tuple_helper>))::type::tuple;
0164 using expected_results_tuple = std::tuple<int, bool>;
0165 static_assert(
0166 std::is_same<found_results_tuple, expected_results_tuple>::value,
0167 "Unpacked results tuple not correct");
0168
0169 constexpr auto found_actions =
0170 detail::type_collector_t<detail::action_type_extractor, traits1,
0171 traits2<true>, traits2<false>>;
0172 constexpr auto expected_actions =
0173 hana::make_set(hana::type_c<char>, hana::type_c<float>);
0174 static_assert(found_actions == expected_actions,
0175 "Didn't find expected actions");
0176
0177
0178 using found_actions_tuple = decltype(hana::unpack(
0179 found_actions, hana::template_<tuple_helper>))::type::tuple;
0180 using expected_actions_tuple = std::tuple<char, float>;
0181 static_assert(
0182 std::is_same<found_actions_tuple, expected_actions_tuple>::value,
0183 "Unpacked actions tuple not correct");
0184 }
0185
0186 BOOST_AUTO_TEST_CASE(has_duplicates_test) {
0187 using detail::has_duplicates_v;
0188 static_assert(has_duplicates_v<int, float, char, int>,
0189 "has_duplicates_v failed");
0190 static_assert(has_duplicates_v<int, int, char, float>,
0191 "has_duplicates_v failed");
0192 static_assert(has_duplicates_v<int, char, float, float>,
0193 "has_duplicates_v failed");
0194 static_assert(has_duplicates_v<int, char, char, float>,
0195 "has_duplicates_v failed");
0196 static_assert(!has_duplicates_v<int, bool, char, float>,
0197 "has_duplicates_v failed");
0198 }
0199
0200 BOOST_AUTO_TEST_CASE(any_of_test) {
0201 using detail::any_of_v;
0202
0203 static_assert(any_of_v<true, true, false>,
0204 "any_of_v<true, true, false> failed");
0205 static_assert(any_of_v<false, true, true, false>,
0206 "any_of_v<false, true, true, false> failed");
0207 static_assert(any_of_v<true, true, true>,
0208 "any_of_v<true, true, true> failed");
0209 static_assert(!any_of_v<false, false>, "any_of_v<false, false> failed");
0210 static_assert(any_of_v<true>, "any_of_v<true> failed");
0211 static_assert(!any_of_v<false>, "any_of_v<false> failed");
0212 static_assert(!any_of_v<>, "any_of_v<> failed");
0213 }
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235 BOOST_AUTO_TEST_CASE(are_sorted_helper_tests) {
0236 using detail::are_sorted;
0237
0238 BOOST_CHECK((are_sorted<true, true, int, -1, 3, 4, 12>::value));
0239 BOOST_CHECK((!are_sorted<true, true, int, -1, 13, 4>::value));
0240 BOOST_CHECK((!are_sorted<true, true, int, -1, 4, 4, 7>::value));
0241
0242 BOOST_CHECK((are_sorted<true, false, int, -1, 3, 4, 12>::value));
0243 BOOST_CHECK((!are_sorted<true, false, int, -1, 13, 4>::value));
0244 BOOST_CHECK((are_sorted<true, false, int, -1, 4, 4, 7>::value));
0245
0246 BOOST_CHECK((are_sorted<false, true, int, 1, -3, -4, -12>::value));
0247 BOOST_CHECK((!are_sorted<false, true, int, 1, -13, -4>::value));
0248 BOOST_CHECK((!are_sorted<false, true, int, 1, -4, -4>::value));
0249
0250 BOOST_CHECK((are_sorted<false, false, int, 1, -3, -4, -12>::value));
0251 BOOST_CHECK((!are_sorted<false, false, int, -1, -13, -4>::value));
0252 BOOST_CHECK((are_sorted<false, false, int, -1, -4, -4, -7>::value));
0253 }
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271 BOOST_AUTO_TEST_CASE(are_within_helper_tests) {
0272 using detail::are_within;
0273 BOOST_CHECK((are_within<int, 0, 10, 1, 3, 7, 2>::value));
0274 BOOST_CHECK((are_within<int, 0, 10, 1, 3, 0, 2>::value));
0275 BOOST_CHECK((!are_within<int, 0, 10, -1, 3, 7, 2>::value));
0276 BOOST_CHECK((!are_within<int, 0, 10, -1, 3, 7, -2>::value));
0277 BOOST_CHECK((!are_within<int, 0, 10, 1, 3, 17, 2>::value));
0278 BOOST_CHECK((!are_within<int, 0, 10, 1, 3, 17, 12>::value));
0279 BOOST_CHECK((!are_within<int, 0, 10, 1, 10>::value));
0280 BOOST_CHECK((!are_within<int, 0, 10, 1, -2, 10, 14>::value));
0281 }
0282
0283
0284
0285
0286 BOOST_AUTO_TEST_CASE(at_index_helper_tests) {
0287 using detail::at_index;
0288 BOOST_CHECK_EQUAL((at_index<int, 0, 10, 1, 3, 7, 2>::value), 10);
0289 BOOST_CHECK_EQUAL((at_index<int, 1, 10, 1, 3, 7, 2>::value), 1);
0290 BOOST_CHECK_EQUAL((at_index<int, 2, 10, 1, 3, 7, 2>::value), 3);
0291 BOOST_CHECK_EQUAL((at_index<int, 3, 10, 1, 3, 7, 2>::value), 7);
0292 BOOST_CHECK_EQUAL((at_index<int, 4, 10, 1, 3, 7, 2>::value), 2);
0293 }
0294 }
0295
0296 }