math_test.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include "gtest/gtest.h"
20 
21 namespace cartographer {
22 namespace common {
23 namespace {
24 
25 TEST(MathTest, testPower) {
26  EXPECT_EQ(0., Power(0, 42));
27  EXPECT_EQ(1., Power(0, 0));
28  EXPECT_EQ(1., Power(1, 0));
29  EXPECT_EQ(1., Power(1, 42));
30  EXPECT_EQ(4., Power(2, 2));
31 }
32 
33 TEST(MathTest, testPow2) {
34  EXPECT_EQ(0., Pow2(0));
35  EXPECT_EQ(1., Pow2(1));
36  EXPECT_EQ(4., Pow2(2));
37  EXPECT_EQ(49., Pow2(7));
38 }
39 
40 TEST(MathTest, testDeg2rad) {
41  EXPECT_NEAR(M_PI, DegToRad(180.), 1e-9);
42  EXPECT_NEAR(2. * M_PI, DegToRad(360. - 1e-9), 1e-6);
43 }
44 
45 TEST(MathTest, testRad2deg) {
46  EXPECT_NEAR(180., RadToDeg(M_PI), 1e-9);
47  EXPECT_NEAR(360., RadToDeg(2. * M_PI - 1e-9), 1e-6);
48 }
49 
50 TEST(MathTest, testNormalizeAngleDifference) {
51  EXPECT_NEAR(0., NormalizeAngleDifference(0.), 1e-9);
52  EXPECT_NEAR(M_PI, NormalizeAngleDifference(M_PI), 1e-9);
53  EXPECT_NEAR(-M_PI, NormalizeAngleDifference(-M_PI), 1e-9);
54  EXPECT_NEAR(0., NormalizeAngleDifference(2. * M_PI), 1e-9);
55  EXPECT_NEAR(M_PI, NormalizeAngleDifference(5. * M_PI), 1e-9);
56  EXPECT_NEAR(-M_PI, NormalizeAngleDifference(-5. * M_PI), 1e-9);
57 }
58 
59 } // namespace
60 } // namespace common
61 } // namespace cartographer
constexpr T Pow2(T a)
Definition: math.h:50
constexpr double RadToDeg(double rad)
Definition: math.h:58
constexpr T Power(T base, int exponent)
Definition: math.h:44
constexpr double DegToRad(double deg)
Definition: math.h:55
T NormalizeAngleDifference(T difference)
Definition: math.h:62
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58