Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 }
00067 }
00068 }