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/tests/tests.hpp"
25 #include "values/math/real.hpp"
26 #include "values/math/imag.hpp"
27 
28 namespace OpenKalman::test
29 {
34 #ifdef __cpp_concepts
35  template<values::value Arg1, values::value Arg2, values::value Err>
36  struct TestComparison<Arg1, Arg2, Err>
37 #else
38  template<typename Arg1, typename Arg2, typename Err>
39  struct TestComparison<Arg1, Arg2, Err, std::enable_if_t<values::value<Arg1> and values::value<Arg2> and values::value<Err>>>
40 #endif
41  : ::testing::AssertionResult
42  {
43  private:
44 
45  template<typename Arg>
46  static auto print(Arg&& arg)
47  {
48  if constexpr (values::complex<Arg>)
49  {
50  return std::to_string(values::real(arg)) + " + " + std::to_string(values::imag(arg)) + "i";
51  }
52  else
53  {
54  return std::forward<Arg>(arg);
55  }
56  }
57 
58 
59  static ::testing::AssertionResult
60  compare(const Arg1 arg1, const Arg2 arg2, const Err& err)
61  {
62  if (values::internal::near(arg1, arg2, err))
63  return ::testing::AssertionSuccess();
64  else
65  return ::testing::AssertionFailure() << print(values::to_number(arg2)) << " is not within " <<
66  print(values::to_number(err)) << " of " << print(values::to_number(arg1));
67  }
68 
69  public:
70 
71  TestComparison(const Arg1& arg1, const Arg2& arg2, const Err& err)
72  : ::testing::AssertionResult {compare(arg1, arg2, err)} {}
73  };
74 
75 } // namespace OpenKalman::test
76 
77 
78 #endif //OPENKALMAN_VALUES_TESTS_HPP
Definition for values::to_number.
constexpr partial_ordering compare(const Lhs &lhs, const Rhs &rhs)
Compare two collections.
Definition: compare.hpp:106
constexpr auto imag(Arg arg)
A constexpr function to obtain the imaginary part of a (complex) number.
Definition: imag.hpp:40
Definition: tuple_reverse.hpp:103
Definition: tests.hpp:41
constexpr auto to_number(Arg arg)
Convert any values::value to a values::number.
Definition: to_number.hpp:34
Definition for values::imag.
Definition: tests.hpp:27
constexpr auto real(Arg arg)
A constexpr function to obtain the real part of a (complex) number.
Definition: real.hpp:40
constexpr bool near(const Arg1 &arg1, const Arg2 &arg2)
Determine whether two numbers are within a rounding tolerance.
Definition: near.hpp:36
Definition for values::real.
Definition for ::complex.
Definition for ::value.