trigonometry_utils_test.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 
3 #include <limits>
4 #include "../../src/core/math_utils.h"
5 #include "../../src/core/trigonometry_utils.h"
6 
7 //----------------------------------------------------------------------------//
8 // Cached Trigorometry Provider Test
9 
10 class CachedTrigonometryProviderTest : public ::testing::Test {
11 protected: // consts
12  static constexpr double Acc_Trig_Err = std::numeric_limits<double>::epsilon();
13 protected: // methods
14  void verify_cache(CachedTrigonometryProvider &ctp, double rotation,
15  double min, double max, double step) {
16  ctp.set_base_angle(rotation);
17  for (double a = min; a < max; a += step) {
18  ASSERT_NEAR(std::cos(a + rotation), ctp.cos(a), Acc_Trig_Err);
19  ASSERT_NEAR(std::sin(a + rotation), ctp.sin(a), Acc_Trig_Err);
20  }
21  }
22 };
23 
24 TEST_F(CachedTrigonometryProviderTest, sector135Step30NoRotation) {
25  const double Min = deg2rad(-135), Max = deg2rad(135), Step = deg2rad(30);
26 
27  auto ctp = CachedTrigonometryProvider{};
28  ctp.update(Min, Max, Step);
29  verify_cache(ctp, 0, Min, Max, Step);
30 }
31 
32 TEST_F(CachedTrigonometryProviderTest, sector120Step7Rotation3) {
33  const double Min = deg2rad(-120), Max = deg2rad(120), Step = deg2rad(7),
34  D_Theta = deg2rad(3);
35 
36  auto ctp = CachedTrigonometryProvider{};
37  ctp.update(Min, Max, Step);
38  verify_cache(ctp, D_Theta, Min, Max, Step);
39 }
40 
41 //----------------------------------------------------------------------------//
42 
43 int main (int argc, char *argv[]) {
44  ::testing::InitGoogleTest(&argc, argv);
45  return RUN_ALL_TESTS();
46 }
int main(int argc, char *argv[])
void set_base_angle(double angle_rad) override
double cos(double angle_rad) const override
void update(double a_min, double a_max, double a_inc)
void verify_cache(CachedTrigonometryProvider &ctp, double rotation, double min, double max, double step)
constexpr double deg2rad(double angle_deg)
Definition: math_utils.h:56
double sin(double angle_rad) const override
TEST_F(CachedTrigonometryProviderTest, sector135Step30NoRotation)


slam_constructor
Author(s): JetBrains Research, OSLL team
autogenerated on Mon Jun 10 2019 15:08:25