Sequoia
Loading...
Searching...
No Matches
ElementaryFreeDiagnosticsUtilities.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2022. //
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
13
14namespace sequoia::testing
15{
16 struct bland
17 {
18 [[nodiscard]]
19 std::string operator()(int, int) const
20 {
21 return "Integer advice";
22 }
23
24 [[nodiscard]]
25 std::string operator()(double, double) const
26 {
27 return "Double advice";
28 }
29 };
30
32 {
33 int i{};
34
35 [[nodiscard]]
36 friend constexpr auto operator<=>(const perfectly_normal_type&, const perfectly_normal_type&) = default;
37 };
38
39 template<>
41 {
42 template<test_mode Mode, class Advisor>
43 static void test(equality_check_t, test_logger<Mode>& logger, const perfectly_normal_type& obtained, const perfectly_normal_type& prediction, const tutor<Advisor>& advisor)
44 {
45 check(equality, "Wrapped value", logger, obtained.i, prediction.i, advisor);
46 }
47
48 template<test_mode Mode, class Advisor>
49 static void test(equivalence_check_t, test_logger<Mode>& logger, const perfectly_normal_type& f, int i, const tutor<Advisor>& advisor)
50 {
51 check(equality, "Wrapped value", logger, f.i, i, advisor);
52 }
53
54 template<test_mode Mode, class Advisor>
55 static void test(weak_equivalence_check_t, test_logger<Mode>& logger, const perfectly_normal_type& f, double d, const tutor<Advisor>& advisor)
56 {
57 check(equality, "Wrapped value", logger, f.i, static_cast<int>(d), advisor);
58 }
59 };
60
62 {
63 int i{};
64
65 [[nodiscard]]
66 friend constexpr auto operator<=>(const perfectly_serializable_type&, const perfectly_serializable_type&) = default;
67
68 friend std::ostream& operator<<(std::ostream& s, const perfectly_serializable_type& x)
69 {
70 return s << x.i;
71 }
72 };
73
75 {
76 int i{};
77
78 [[nodiscard]]
79 friend constexpr auto operator<=>(const perfectly_nonserializable_type&, const perfectly_nonserializable_type&) = default;
80 };
81
82 template<>
84 {
85 [[nodiscard]]
86 static std::string make(const perfectly_nonserializable_type& x) { return std::format("{}", x.i); }
87 };
88
90 {
91 only_equivalence_checkable(double val) : x{val} {}
92
93 double x{};
94 };
95
97 {
98 only_weakly_checkable(int j, double y) : i{j}, x{y} {}
99
100 int i{};
101 double x{};
102 };
103
104 template<>
106 {
107 template<test_mode Mode, class Advisor>
108 static void test(equivalence_check_t, test_logger<Mode>& logger, const only_equivalence_checkable& obtained, double prediction, const tutor<Advisor>& advisor)
109 {
110 check(equality, "Wrapped double", logger, obtained.x, prediction, advisor);
111 }
112
113 template<test_mode Mode, class Advisor>
114 static void test(equivalence_check_t, test_logger<Mode>& logger, const only_equivalence_checkable& obtained, const only_equivalence_checkable& prediction, const tutor<Advisor>& advisor)
115 {
116 check(equality, "Wrapped double", logger, obtained.x, prediction.x, advisor);
117 }
118 };
119
120 template<>
122 {
123 template<test_mode Mode, class Advisor>
124 static void test(weak_equivalence_check_t, test_logger<Mode>& logger, const only_weakly_checkable& obtained, const std::pair<int, double>& prediction, const tutor<Advisor>& advisor)
125 {
126 check(equality, "Wrapped int", logger, obtained.i, prediction.first, advisor);
127 check(equality, "Wrapped double", logger, obtained.x, prediction.second, advisor);
128 }
129
130 template<test_mode Mode, class Advisor>
131 static void test(weak_equivalence_check_t, test_logger<Mode>& logger, const only_weakly_checkable& obtained, const only_weakly_checkable& prediction, const tutor<Advisor>& advisor)
132 {
133 check(equality, "Wrapped int", logger, obtained.i, prediction.i, advisor);
134 check(equality, "Wrapped double", logger, obtained.x, prediction.x, advisor);
135 }
136 };
137}
Free functions for performing checks, together with the 'checker' class template which wraps them.
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
Definition: TestLogger.hpp:183
class template used to wrap function objects which proffer advice.
Definition: Advice.hpp:127
Definition: ElementaryFreeDiagnosticsUtilities.hpp:17
Definition: FreeCheckers.hpp:82
Definition: FreeCheckers.hpp:87
Definition: ElementaryFreeDiagnosticsUtilities.hpp:90
Definition: ElementaryFreeDiagnosticsUtilities.hpp:97
Definition: ElementaryFreeDiagnosticsUtilities.hpp:75
Definition: ElementaryFreeDiagnosticsUtilities.hpp:32
Definition: ElementaryFreeDiagnosticsUtilities.hpp:62
Specialize this struct template to provide custom serialization of a given class. .
Definition: CoreInfrastructure.hpp:28
class template, specializations of which implement various comparisons for the specified type.
Definition: FreeCheckers.hpp:78