TestHelpers.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
7 
8 #include <memory>
9 #include <string>
10 #include <tuple>
11 #include <type_traits>
12 #include <unordered_map>
13 #include <utility>
14 
15 #include "Domain/FunctionsOfTime/FunctionOfTime.hpp"
16 #include "Utilities/Tuple.hpp"
17 
18 namespace TestHelpers {
19 namespace domain {
20 namespace creators {
21 template <typename Creator, typename... ExpectedFunctionsOfTime>
22 void test_functions_of_time(
23  const Creator& creator,
25  expected_functions_of_time) {
26  const std::unordered_map<
28  functions_of_time = creator.functions_of_time();
29  REQUIRE(functions_of_time.size() == sizeof...(ExpectedFunctionsOfTime));
30 
31  tuple_fold(
32  expected_functions_of_time,
33  [&functions_of_time](const auto& name_and_function_of_time) noexcept {
34  const std::string& name = name_and_function_of_time.first;
35  const auto& function_of_time = name_and_function_of_time.second;
36  using FunctionOfTimeType = std::decay_t<decltype(function_of_time)>;
37  const bool in_functions_of_time =
38  functions_of_time.find(name) != functions_of_time.end();
39  CHECK(in_functions_of_time);
40  if (in_functions_of_time) {
41  const auto* function_from_creator =
42  dynamic_cast<const FunctionOfTimeType*>(
43  functions_of_time.at(name).get());
44  REQUIRE(function_from_creator != nullptr);
45  CHECK(*function_from_creator == function_of_time);
46  }
47  });
48 }
49 } // namespace creators
50 } // namespace domain
51 } // namespace TestHelpers
std::string
utility
std::pair
TestingFramework.hpp
tuple
tuple_fold
constexpr void tuple_fold(const std::tuple< Elements... > &tuple, N_aryOp &&op, Args &&... args) noexcept(noexcept(tuple_impl_detail::tuple_fold_impl< ReverseIteration >(tuple, std::forward< N_aryOp >(op), std::make_index_sequence< sizeof...(Elements)>{}, args...)))
Perform a fold over a std::tuple.
Definition: Tuple.hpp:112
Tuple.hpp
memory
std::decay_t
std::unique_ptr
unordered_map
type_traits
string