16 #ifndef OPENKALMAN_LINEAR_ALGEBRA_TESTS_HPP 17 #define OPENKALMAN_LINEAR_ALGEBRA_TESTS_HPP 33 template<indexible Arg1, indexible Arg2,
typename Err> requires
34 (index_count_v<Arg1> == index_count_v<Arg2>) and
35 (values::value<Err> or (indexible<Err> and index_count_v<Err> == index_count_v<Arg1>)) and
36 (not collections::collection<Arg1> or not collections::collection<Arg2>)
37 struct TestComparison<Arg1, Arg2, Err>
39 template<typename Arg1, typename Arg2, typename Err>
41 indexible<Arg1> and indexible<Arg2> and
42 (index_count<Arg1>::value == index_count<Arg2>::value) and
43 (values::value<Err> or indexible<Err>) and
44 (not collections::collection<Arg1> or not collections::collection<Arg2>)>>
46 : ::testing::AssertionResult
51 print_indices() {
return std::string{
"()"}; }
53 template<
typename I,
typename...Is>
55 print_indices(I i, Is...is) {
return std::string{
"("} + (std::to_string(i) + ... + (
", " + std::to_string(is))) +
")"; }
58 template<
typename...Ix>
59 static ::testing::AssertionResult
60 compare_mdspan(
const Arg1& arg1,
const Arg2& arg2,
const Err& err, Ix...ix)
62 constexpr std::size_t ind =
sizeof...(Ix);
63 if constexpr (ind < index_count_v<Arg1>)
65 auto dim1 = get_index_extent<ind>(arg1);
66 auto dim2 = get_index_extent<ind>(arg2);
67 if (dim1 != dim2) return ::testing::AssertionFailure() <<
"Dimensions do not match for index" <<
68 std::to_string(ind) <<
" (" << std::to_string(dim1) <<
" != " << std::to_string(dim2) <<
")";
70 for (std::size_t i = 0; i < get_index_extent<ind>(arg1); ++i)
71 msg += compare_mdspan(arg1, arg2, err, ix..., i).message();
72 if (msg.size() == 0) return ::testing::AssertionSuccess();
73 return ::testing::AssertionFailure() << msg;
77 auto indices = std::array{ix...};
78 auto e = [&]{
if constexpr (indexible<Err>)
return err[indices];
else return err; }();
80 if (res) return ::testing::AssertionSuccess();
81 return ::testing::AssertionFailure() << print_indices(ix...) <<
": " << res.message() << std::endl;
88 : ::testing::AssertionResult {compare_mdspan(arg1, arg2, err)} {};
constexpr auto get_mdspan(T &t)
Get the coordinates::pattern_collection associated with indexible object T.
Definition: get_mdspan.hpp:35
Definition of get_index_extent function.
Inclusion file for collections.
Definition of get_mdspan function.
Definition for index_count.
Definition for indexible.