Sequoia
Loading...
Searching...
No Matches
MonotonicSequenceTestingUtilities.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2019. //
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
15
16namespace sequoia::testing
17{
18 namespace impl
19 {
20 template<test_mode Mode, class T>
21 void check(test_logger<Mode>& logger, const T& sequence, const T& prediction)
22 {
23 check(equality, "Emptiness incorrect", logger, sequence.empty(), prediction.empty());
24
25 if(check(equality, "Size incorrect", logger, sequence.size(), prediction.size()))
26 {
27 if(!prediction.empty())
28 {
29 check(equality, "Back element wrong", logger, sequence.back(), prediction.back());
30 check(equality, "Front element wrong", logger, sequence.front(), prediction.front());
31 }
32
33 auto i_prediction{prediction.begin()}, i{sequence.begin()};
34 auto ci_prediction{prediction.cbegin()}, ci{sequence.cbegin()};
35 auto ri_prediction{prediction.rbegin()}, ri{sequence.rbegin()};
36 auto cri_prediction{prediction.crbegin()}, cri{sequence.crbegin()};
37
38 for(;i_prediction != prediction.end(); ++i_prediction, ++i, ++ci_prediction, ++ci, ++ri_prediction, ++ri, ++cri_prediction, ++cri)
39 {
40 const auto d{std::ranges::distance(prediction.begin(), i_prediction)};
41 const auto mess{std::string{" for index "}.append(std::to_string(d))};
42
43 check(equality, std::string{"Dereferenced iterator wrong"}.append(mess), logger, *i, *i_prediction);
44 check(equality, std::string{"Dereferenced citerator wrong"}.append(mess), logger, *ci, *ci_prediction);
45
46 check(equality, std::string{"operator[] wrong"}.append(mess), logger, sequence[d], prediction[d]);
47
48 const auto shift{static_cast<int64_t>(prediction.size()) - d - 1};
49 check(equality, std::string{"Dereferenced riterator wrong"}.append(mess), logger, *(ri + shift), *(ri_prediction + shift));
50 check(equality, std::string{"Dereferenced criterator wrong"}.append(mess), logger, *(cri + shift), *(cri_prediction + shift));
51 }
52
53 testing::check("iterator location wrong", logger, i_prediction == prediction.end());
54 testing::check("citerator location wrong", logger, ci_prediction == prediction.cend());
55 testing::check("riterator location wrong", logger, ri_prediction == prediction.rend());
56 testing::check("criterator location wrong", logger, cri_prediction == prediction.crend());
57 }
58 }
59 }
60
61 template<class T, class C, class Compare>
62 struct value_tester<maths::monotonic_sequence<T, C, Compare>>
63 {
65
66 template<test_mode Mode>
67 static void test(equality_check_t, test_logger<Mode>& logger, const type& sequence, const type& prediction)
68 {
69 impl::check(logger, sequence, prediction);
70 }
71
72 template<test_mode Mode>
73 static void test(equivalence_check_t, test_logger<Mode>& logger, const type& sequence, std::initializer_list<T> prediction)
74 {
75 check(equality, "", logger, sequence.begin(), sequence.end(), prediction.begin(), prediction.end());
76 }
77 };
78
79 template<class T, std::size_t N, class Compare>
80 struct value_tester<maths::static_monotonic_sequence<T, N, Compare>>
81 {
83
84 template<test_mode Mode>
85 static void test(equality_check_t, test_logger<Mode>& logger, const type& sequence, const type& prediction)
86 {
87 impl::check(logger, sequence, prediction);
88 }
89
90 template<test_mode Mode>
91 static void test(equivalence_check_t, test_logger<Mode>& logger, const type& sequence, std::initializer_list<T> prediction)
92 {
93 check(equality, "", logger, sequence.begin(), sequence.end(), prediction.begin(), prediction.end());
94 }
95 };
96}
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
Classes implementing the concept of a monotonic sequence.
Utilities for checking regular semantics.
Definition: MonotonicSequence.hpp:248
Definition: MonotonicSequence.hpp:303
Definition: TestLogger.hpp:183
Definition: FreeCheckers.hpp:82
Definition: FreeCheckers.hpp:87
class template, specializations of which implement various comparisons for the specified type.
Definition: FreeCheckers.hpp:78