Sequoia
Loading...
Searching...
No Matches
FactoryTestingUtilities.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2021. //
3// Distributed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. //
4// (See accompanying file LICENSE.md or copy at //
5// https://www.gnu.org/licenses/gpl-3.0.en.html) //
7
8#pragma once
9
14
15#include <map>
16
17namespace sequoia::testing
18{
19 template<class... Products>
20 struct value_tester<sequoia::object::factory<Products...>>
21 {
22 using type = sequoia::object::factory<Products...>;
23 using element = std::pair<std::string, std::variant<Products...>>;
24
25 template<class... Args>
26 using factory_check_type = general_equivalence_check_t<std::tuple<Args...>>;
27
28 template<test_mode Mode, class... Args>
29 requires (initializable_from<Products, Args...> && ... )
30 static void test(factory_check_type<Args...> equivChecker, test_logger<Mode>& logger, const type& actual, const std::array<element, sizeof...(Products)>& prediction)
31 {
32 for(const auto&[name, product] : prediction)
33 {
34 const auto message{std::string{"Product generated by name '"}.append(name).append("'")};
35 auto maker{
36 [&actual, &name](const Args&... args){
37 return actual.make(name, args...);
38 }
39 };
40 check(equality, message, logger, std::apply(maker, equivChecker.customizer), product);
41 }
42 }
43
44 template<test_mode Mode>
45 static void test(equivalence_check_t, test_logger<Mode>& logger, const type& actual, const std::array<element, sizeof...(Products)>& prediction)
46 {
47 for(const auto&[name, product] : prediction)
48 {
49 const auto message{std::string{"Product generated by name '"}.append(name).append("'")};
50 check(equality, message, logger, actual.make(name), product);
51 }
52 }
53
54
55 template<test_mode Mode>
56 static void test(equality_check_t, test_logger<Mode>& logger, const type& actual, const type& prediction)
57 {
58 check(equality, "Names", logger, actual.begin_names(), actual.end_names(), prediction.begin_names(), prediction.end_names());
59 }
60 };
61}
Factory implementation(s)
bool check(CheckType flavour, std::string description, test_logger< Mode > &logger, Iter first, Sentinel last, PredictionIter predictionFirst, PredictionSentinel predictionLast, tutor< Advisor > advisor={})
The workhorse for comparing the contents of ranges.
Definition: FreeCheckers.hpp:377
Utilities for checking regular semantics.
Generic factory with statically defined products.
Definition: Factory.hpp:68
Definition: TestLogger.hpp:183
A concept similar to std::constructible_from, but which considers braced-init.
Definition: Concepts.hpp:75
Definition: FreeCheckers.hpp:82
Definition: FreeCheckers.hpp:87
class template, specializations of which implement various comparisons for the specified type.
Definition: FreeCheckers.hpp:78