17 #ifndef OPENKALMAN_COLLECTIONS_TESTS_HPP 18 #define OPENKALMAN_COLLECTIONS_TESTS_HPP 38 template<collections::collection Arg1, collections::collection Arg2,
typename Err> requires
39 (collections::uniformly_gettable<Arg1> and collections::uniformly_gettable<Arg2> and
40 (collections::uniformly_gettable<Err> or values::value<Err>)) or
41 (stdex::ranges::range<Arg1> and stdex::ranges::range<Arg2> and
42 (stdex::ranges::range<Err> or values::value<Err>))
43 struct TestComparison<Arg1, Arg2, Err>
45 template<typename Arg1, typename Arg2, typename Err>
47 collections::collection<Arg1> and collections::collection<Arg2> and
48 ((collections::uniformly_gettable<Arg1> and collections::uniformly_gettable<Arg2> and
49 (collections::uniformly_gettable<Err> or values::value<Err>)) or
50 (stdex::ranges::range<Arg1> and stdex::ranges::range<Arg2> and
51 (stdex::ranges::range<Err> or values::value<Err>)))>>
53 : ::testing::AssertionResult
57 template<std::size_t...Ix>
61 if constexpr (collections::uniformly_gettable<Err>)
65 return ::testing::AssertionSuccess();
69 return (::testing::AssertionFailure() << ... << (std::string(Ix == 0 ?
"" :
", ") +
71 std::to_string(collections::get<Ix>(arg1)) +
"==" + std::to_string(collections::get<Ix>(arg2)) :
72 std::to_string(collections::get<Ix>(arg1)) +
"!=" + std::to_string(collections::get<Ix>(arg2)) )));
79 return ::testing::AssertionSuccess();
83 return (::testing::AssertionFailure() << ... << (std::string(Ix == 0 ?
"" :
", ") +
85 std::to_string(collections::get<Ix>(arg1)) +
" == " + std::to_string(collections::get<Ix>(arg2)) :
86 std::to_string(collections::get<Ix>(arg1)) +
" != " + std::to_string(collections::get<Ix>(arg2)) )));
92 template<
typename A1,
typename A2,
typename E,
typename...Ix>
94 compare_mdarray(
const A1& a1,
const A2& a2,
const E& e, std::string& message, Ix...ix)
96 static_assert(std::rank_v<A1> == std::rank_v<A2>);
97 if constexpr (std::rank_v<A1> > 0)
99 static_assert(std::extent_v<A1> == std::extent_v<A2>,
"extents of arguments must match");
100 static_assert(not std::is_array_v<Err> or std::extent_v<E> == std::extent_v<A1>,
"extents of error argument must match other arguments");
102 for (std::size_t i = 0; i < std::extent_v<A1>; ++i)
104 if constexpr (std::is_array_v<Err>)
106 if (not compare_mdarray(a1[i], a2[i], e[i], message, ix..., i)) success =
false;
110 if (not compare_mdarray(a1[i], a2[i], e, message, ix..., i)) success =
false;
118 message += (
"" + ... + (
" " + std::to_string(ix))) +
": " + std::to_string(a1) +
119 "!=" + std::to_string(a2) +
"(±" + std::to_string(e) +
"). ";
125 template<std::size_t...Ix>
127 compare(
const Arg1& arg1,
const Arg2& arg2,
const Err& err)
131 "size of arguments must match");
133 static_assert(values::value<Err> or
135 "size of error margins must match that of arguments");
137 if constexpr (std::rank_v<Arg1> > 1 and std::rank_v<Arg1> == std::rank_v<Arg2> and (std::rank_v<Err> == std::rank_v<Arg1> or values::value<Err>))
140 if (compare_mdarray(arg1, arg2, err, message)) return ::testing::AssertionSuccess();
141 else return ::testing::AssertionFailure() << message;
143 else if constexpr (collections::uniformly_gettable<Arg1> and collections::uniformly_gettable<Arg2>)
145 return compare_tuple_like(arg1, arg2, err, std::make_index_sequence<collections::size_of_v<Arg1>>{});
151 auto it1 = stdex::ranges::begin(arg1);
152 auto it2 = stdex::ranges::begin(arg2);
153 std::size_t count = 0;
154 if constexpr (stdex::ranges::range<Err>)
156 for (
auto ite = stdex::ranges::begin(err);
157 it1 != stdex::ranges::end(arg1) and it2 != stdex::ranges::end(arg2) and ite != stdex::ranges::end(err);
158 ++it1, ++it2, ++ite, ++count)
163 message += std::to_string(count) +
": " + std::to_string(*it1) +
"!=" + std::to_string(*it2) +
164 "(±" + std::to_string(*ite) +
"). ";
170 for (; it1 != stdex::ranges::end(arg1) and it2 != stdex::ranges::end(arg2); ++it1, ++it2, ++count)
175 message += std::to_string(count) +
": " + std::to_string(*it1) +
"!=" + std::to_string(*it2) +
176 "(±" + std::to_string(err) +
"). ";
180 if (success) return ::testing::AssertionSuccess();
181 else return ::testing::AssertionFailure() << message;
187 TestComparison(
const Arg1& arg1,
const Arg2& arg2,
const Err& err)
188 : ::testing::AssertionResult {
compare(arg1, arg2, err)} {}
Definition for collections::get.
Definition for collections::collection.
Header file for code relating to values (e.g., scalars and indices)
constexpr auto compare(const A &a, const B &b)
Compare two coordinates::pattern objects lexicographically.
Definition: compare.hpp:40
Definition for collections::size_of.
The size of a sized object (including a collection).
Definition: size_of.hpp:33
constexpr bool size_compares_with
T and U are sizes that compare in a particular way based on parameter comp.
Definition: size_compares_with.hpp:98
Basic utilities for OpenKalman testing.
Definition: trait_backports.hpp:64