math_test.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "cartographer/common/math.h"
00018 
00019 #include "gtest/gtest.h"
00020 
00021 namespace cartographer {
00022 namespace common {
00023 namespace {
00024 
00025 TEST(MathTest, testPower) {
00026   EXPECT_EQ(0., Power(0, 42));
00027   EXPECT_EQ(1., Power(0, 0));
00028   EXPECT_EQ(1., Power(1, 0));
00029   EXPECT_EQ(1., Power(1, 42));
00030   EXPECT_EQ(4., Power(2, 2));
00031 }
00032 
00033 TEST(MathTest, testPow2) {
00034   EXPECT_EQ(0., Pow2(0));
00035   EXPECT_EQ(1., Pow2(1));
00036   EXPECT_EQ(4., Pow2(2));
00037   EXPECT_EQ(49., Pow2(7));
00038 }
00039 
00040 TEST(MathTest, testDeg2rad) {
00041   EXPECT_NEAR(M_PI, DegToRad(180.), 1e-9);
00042   EXPECT_NEAR(2. * M_PI, DegToRad(360. - 1e-9), 1e-6);
00043 }
00044 
00045 TEST(MathTest, testRad2deg) {
00046   EXPECT_NEAR(180., RadToDeg(M_PI), 1e-9);
00047   EXPECT_NEAR(360., RadToDeg(2. * M_PI - 1e-9), 1e-6);
00048 }
00049 
00050 TEST(MathTest, testNormalizeAngleDifference) {
00051   EXPECT_NEAR(0., NormalizeAngleDifference(0.), 1e-9);
00052   EXPECT_NEAR(M_PI, NormalizeAngleDifference(M_PI), 1e-9);
00053   EXPECT_NEAR(-M_PI, NormalizeAngleDifference(-M_PI), 1e-9);
00054   EXPECT_NEAR(0., NormalizeAngleDifference(2. * M_PI), 1e-9);
00055   EXPECT_NEAR(M_PI, NormalizeAngleDifference(5. * M_PI), 1e-9);
00056   EXPECT_NEAR(-M_PI, NormalizeAngleDifference(-5. * M_PI), 1e-9);
00057 }
00058 
00059 }  // namespace
00060 }  // namespace common
00061 }  // namespace cartographer


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:35