tsd_value_converter_test.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2018 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/mapping/2d/tsd_value_converter.h"
00018 
00019 #include "gtest/gtest.h"
00020 
00021 namespace cartographer {
00022 namespace mapping {
00023 namespace {
00024 
00025 class TSDValueConverterTest : public ::testing::Test {
00026  protected:
00027   TSDValueConverterTest()
00028       : truncation_distance_(0.1f),
00029         max_weight_(10.0f),
00030         tsd_value_converter_(truncation_distance_, max_weight_,
00031                              &conversion_tables) {}
00032   ValueConversionTables conversion_tables;
00033   float truncation_distance_;
00034   float max_weight_;
00035   TSDValueConverter tsd_value_converter_;
00036 };
00037 
00038 TEST_F(TSDValueConverterTest, DefaultValues) {
00039   EXPECT_EQ(tsd_value_converter_.getUnknownWeightValue(), 0);
00040   EXPECT_EQ(tsd_value_converter_.getUnknownTSDValue(), 0);
00041   EXPECT_EQ(tsd_value_converter_.getMinTSD(), -truncation_distance_);
00042   EXPECT_EQ(tsd_value_converter_.getMaxTSD(), truncation_distance_);
00043   EXPECT_EQ(tsd_value_converter_.getMinWeight(), 0.f);
00044   EXPECT_EQ(tsd_value_converter_.getMaxWeight(), max_weight_);
00045 }
00046 
00047 TEST_F(TSDValueConverterTest, ValueToTSDConversions) {
00048   for (uint16 i = 1; i < 32768; ++i) {
00049     EXPECT_EQ(
00050         tsd_value_converter_.TSDToValue(tsd_value_converter_.ValueToTSD(i)), i);
00051   }
00052 }
00053 
00054 TEST_F(TSDValueConverterTest, ValueToTSDConversionsWithUpdateMarker) {
00055   for (uint16 i = 1; i < 32768; ++i) {
00056     EXPECT_EQ(tsd_value_converter_.TSDToValue(tsd_value_converter_.ValueToTSD(
00057                   i + tsd_value_converter_.getUpdateMarker())),
00058               i);
00059   }
00060 }
00061 
00062 TEST_F(TSDValueConverterTest, ValueToWeightConversions) {
00063   for (uint16 i = 1; i < 32768; ++i) {
00064     EXPECT_EQ(tsd_value_converter_.WeightToValue(
00065                   tsd_value_converter_.ValueToWeight(i)),
00066               i);
00067   }
00068 }
00069 
00070 TEST_F(TSDValueConverterTest, ValueToWeightConversionsWithUpdateMarker) {
00071   for (uint16 i = 1; i < 32768; ++i) {
00072     EXPECT_EQ(
00073         tsd_value_converter_.WeightToValue(tsd_value_converter_.ValueToWeight(
00074             i + tsd_value_converter_.getUpdateMarker())),
00075         i);
00076   }
00077 }
00078 
00079 TEST_F(TSDValueConverterTest, TSDToValueConversions) {
00080   uint16 num_samples = 1000;
00081   float tolerance = truncation_distance_ * 2.f / 32767.f;
00082   for (uint16 i = 0; i < num_samples; ++i) {
00083     float sdf_sample =
00084         -truncation_distance_ + i * 2.f * truncation_distance_ / num_samples;
00085     EXPECT_NEAR(tsd_value_converter_.ValueToTSD(
00086                     tsd_value_converter_.TSDToValue(sdf_sample)),
00087                 sdf_sample, tolerance);
00088   }
00089 }
00090 
00091 TEST_F(TSDValueConverterTest, WeightToValueConversions) {
00092   uint16 num_samples = 1000;
00093   float tolerance = max_weight_ / 32767.f;
00094   for (uint16 i = 0; i < num_samples; ++i) {
00095     float weight_sample = i * max_weight_ / num_samples;
00096     EXPECT_NEAR(tsd_value_converter_.ValueToWeight(
00097                     tsd_value_converter_.WeightToValue(weight_sample)),
00098                 weight_sample, tolerance);
00099   }
00100 }
00101 
00102 TEST_F(TSDValueConverterTest, WeightToValueOutOfRangeConversions) {
00103   float tolerance = max_weight_ / 32767.f;
00104   EXPECT_NEAR(tsd_value_converter_.ValueToWeight(
00105                   tsd_value_converter_.WeightToValue(2.f * max_weight_)),
00106               max_weight_, tolerance);
00107   EXPECT_NEAR(tsd_value_converter_.ValueToWeight(
00108                   tsd_value_converter_.WeightToValue(-max_weight_)),
00109               0.f, tolerance);
00110 }
00111 
00112 TEST_F(TSDValueConverterTest, TSDToValueOutOfRangeConversions) {
00113   float tolerance = truncation_distance_ * 2.f / 32767.f;
00114   EXPECT_NEAR(tsd_value_converter_.ValueToTSD(
00115                   tsd_value_converter_.TSDToValue(2.f * truncation_distance_)),
00116               truncation_distance_, tolerance);
00117   EXPECT_NEAR(tsd_value_converter_.ValueToTSD(
00118                   tsd_value_converter_.TSDToValue(-2.f * truncation_distance_)),
00119               -truncation_distance_, tolerance);
00120 }
00121 
00122 }  // namespace
00123 }  // namespace mapping
00124 }  // namespace cartographer


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