value_conversion_tables_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/value_conversion_tables.h"
00018 
00019 #include <random>
00020 
00021 #include "gtest/gtest.h"
00022 
00023 namespace cartographer {
00024 namespace mapping {
00025 namespace {
00026 
00027 TEST(ValueConversionTablesTest, EqualTables) {
00028   ValueConversionTables value_conversion_tables;
00029   const std::vector<float>* reference_table =
00030       value_conversion_tables.GetConversionTable(0.1f, 0.1f, 0.5f);
00031   const std::vector<float>* test_table =
00032       value_conversion_tables.GetConversionTable(0.1f, 0.1f, 0.5f);
00033   EXPECT_EQ(reference_table, test_table);
00034 }
00035 
00036 TEST(ValueConversionTablesTest, InequalTables) {
00037   ValueConversionTables value_conversion_tables;
00038   const std::vector<float>* reference_table =
00039       value_conversion_tables.GetConversionTable(0.1f, 0.1f, 0.5f);
00040   const std::vector<float>* test_table =
00041       value_conversion_tables.GetConversionTable(0.1f, 0.4f, 0.5f);
00042   EXPECT_FALSE(reference_table == test_table);
00043 }
00044 
00045 TEST(ValueConversionTablesTest, ValueConversion) {
00046   ValueConversionTables value_conversion_tables;
00047   std::mt19937 rng(42);
00048   std::uniform_real_distribution<float> bound_distribution(-10.f, 10.f);
00049   for (size_t sample_index = 0; sample_index < 100; ++sample_index) {
00050     const float bound_sample_0 = bound_distribution(rng);
00051     const float bound_sample_1 = bound_distribution(rng);
00052     const float lower_bound = std::min(bound_sample_0, bound_sample_1);
00053     const float upper_bound = std::max(bound_sample_0, bound_sample_1);
00054     const float undefined_value = bound_distribution(rng);
00055     const std::vector<float>* conversion_table =
00056         value_conversion_tables.GetConversionTable(undefined_value, lower_bound,
00057                                                    upper_bound);
00058     EXPECT_EQ((*conversion_table)[0], undefined_value);
00059     const float scale = (upper_bound - lower_bound) / 32766.f;
00060     for (uint16 i = 1; i < 32768; ++i) {
00061       EXPECT_EQ((*conversion_table)[i], i * scale + (lower_bound - scale));
00062     }
00063   }
00064 }
00065 
00066 }  // namespace
00067 }  // namespace mapping
00068 }  // namespace cartographer


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