OpenKalman
tests.hpp
Go to the documentation of this file.
1 /* This file is part of OpenKalman, a header-only C++ library for
2  * Kalman filters and other recursive filters.
3  *
4  * Copyright (c) 2017-2024 Christopher Lee Ogden <ogden@gatech.edu>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
9  */
10 
16 #ifndef OPENKALMAN_VALUES_TESTS_HPP
17 #define OPENKALMAN_VALUES_TESTS_HPP
18 
19 #include <string>
20 #include "basics/basics.hpp"
25 #include "values/math/real.hpp"
26 #include "values/math/imag.hpp"
27 #include "basics/tests/tests.hpp"
28 
29 namespace OpenKalman::test
30 {
35 #ifdef __cpp_concepts
36  template<values::value Arg1, values::value Arg2, values::value Err>
37  struct TestComparison<Arg1, Arg2, Err>
38 #else
39  template<typename Arg1, typename Arg2, typename Err>
40  struct TestComparison<Arg1, Arg2, Err, std::enable_if_t<
41  values::value<Arg1> and values::value<Arg2> and values::value<Err>>>
42 #endif
43  : ::testing::AssertionResult
44  {
45  private:
46 
47  template<typename Arg>
48  static auto print(Arg&& arg)
49  {
50  if constexpr (values::complex<Arg>)
51  {
52  return std::to_string(values::real(arg)) + " + " + std::to_string(values::imag(arg)) + "i";
53  }
54  else
55  {
56  return std::forward<Arg>(arg);
57  }
58  }
59 
60 
61  static ::testing::AssertionResult
62  compare(const Arg1& arg1, const Arg2& arg2, const Err& err)
63  {
64  if (values::internal::near(arg1, arg2, err))
65  return ::testing::AssertionSuccess();
66  else
67  return ::testing::AssertionFailure() << print(values::to_value_type(arg2)) << " is not within " <<
68  print(values::to_value_type(err)) << " of " << print(values::to_value_type(arg1));
69  }
70 
71  public:
72 
73  TestComparison(const Arg1& arg1, const Arg2& arg2, const Err& err)
74  : ::testing::AssertionResult {compare(arg1, arg2, err)} {}
75  };
76 
77 }
78 
79 
80 #endif
constexpr auto compare(const A &a, const B &b)
Compare two coordinates::pattern objects lexicographically.
Definition: compare.hpp:40
Definition for values::to_value_type.
decltype(auto) constexpr to_value_type(Arg &&arg)
Convert, if necessary, a fixed or dynamic value to its underlying base type.
Definition: to_value_type.hpp:28
Definition: tests.hpp:36
constexpr auto imag(const Arg &arg)
A constexpr function to obtain the imaginary part of a (complex) number.
Definition: imag.hpp:40
Definition for values::imag.
constexpr auto near(const Arg1 &arg1, const Arg2 &arg2)
Determine whether two numbers are within a rounding tolerance.
Definition: near.hpp:46
Definition: tests.hpp:22
constexpr auto real(const Arg &arg)
A constexpr function to obtain the real part of a (complex) number.
Definition: real.hpp:40
Basic definitions for OpenKalman as a whole.
Definition for values::real.
Definition for values::complex.
Definition for values::value.